| 1 |
;; Machine description for RISC-V for GNU compiler. |
| 2 |
;; Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 3 |
;; Contributed by Andrew Waterman ([email protected]). |
| 4 |
;; Based on MIPS target for GNU compiler. |
| 5 |
|
| 6 |
;; This file is part of GCC. |
| 7 |
|
| 8 |
;; GCC is free software; you can redistribute it and/or modify |
| 9 |
;; it under the terms of the GNU General Public License as published by |
| 10 |
;; the Free Software Foundation; either version 3, or (at your option) |
| 11 |
;; any later version. |
| 12 |
|
| 13 |
;; GCC is distributed in the hope that it will be useful, |
| 14 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
;; GNU General Public License for more details. |
| 17 |
|
| 18 |
;; You should have received a copy of the GNU General Public License |
| 19 |
;; along with GCC; see the file COPYING3. If not see |
| 20 |
;; <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
|
| 23 |
;; Keep this list and the one above riscv_print_operand in sync. |
| 24 |
;; The special asm out single letter directives following a '%' are: |
| 25 |
;; h -- Print the high-part relocation associated with OP, after stripping |
| 26 |
;; any outermost HIGH. |
| 27 |
;; R -- Print the low-part relocation associated with OP. |
| 28 |
;; C -- Print the integer branch condition for comparison OP. |
| 29 |
;; A -- Print the atomic operation suffix for memory model OP. |
| 30 |
;; F -- Print a FENCE if the memory model requires a release. |
| 31 |
;; z -- Print x0 if OP is zero, otherwise print OP normally. |
| 32 |
;; i -- Print i if the operand is not a register. |
| 33 |
;; S -- Print shift-index of single-bit mask OP. |
| 34 |
;; T -- Print shift-index of inverted single-bit mask OP. |
| 35 |
;; ~ -- Print w if TARGET_64BIT is true; otherwise not print anything. |
| 36 |
|
| 37 |
(define_c_enum "unspec" [ |
| 38 |
;; Override return address for exception handling. |
| 39 |
UNSPEC_EH_RETURN |
| 40 |
|
| 41 |
;; Symbolic accesses. The order of this list must match that of |
| 42 |
;; enum riscv_symbol_type in riscv-protos.h. |
| 43 |
UNSPEC_ADDRESS_FIRST |
| 44 |
UNSPEC_FORCE_FOR_MEM |
| 45 |
UNSPEC_PCREL |
| 46 |
UNSPEC_LOAD_GOT |
| 47 |
UNSPEC_TLS |
| 48 |
UNSPEC_TLS_LE |
| 49 |
UNSPEC_TLS_IE |
| 50 |
UNSPEC_TLS_GD |
| 51 |
UNSPEC_TLSDESC |
| 52 |
;; High part of PC-relative address. |
| 53 |
UNSPEC_AUIPC |
| 54 |
|
| 55 |
;; Floating-point unspecs. |
| 56 |
UNSPEC_FLT_QUIET |
| 57 |
UNSPEC_FLE_QUIET |
| 58 |
UNSPEC_COPYSIGN |
| 59 |
UNSPEC_FMV_X_W |
| 60 |
UNSPEC_FMVH_X_D |
| 61 |
UNSPEC_RINT |
| 62 |
UNSPEC_ROUND |
| 63 |
UNSPEC_FLOOR |
| 64 |
UNSPEC_CEIL |
| 65 |
UNSPEC_BTRUNC |
| 66 |
UNSPEC_ROUNDEVEN |
| 67 |
UNSPEC_NEARBYINT |
| 68 |
UNSPEC_LRINT |
| 69 |
UNSPEC_FMIN |
| 70 |
UNSPEC_FMAX |
| 71 |
UNSPEC_FMINM |
| 72 |
UNSPEC_FMAXM |
| 73 |
UNSPEC_FCLASS |
| 74 |
|
| 75 |
;; Stack tie |
| 76 |
UNSPEC_TIE |
| 77 |
|
| 78 |
;; OR-COMBINE |
| 79 |
UNSPEC_ORC_B |
| 80 |
|
| 81 |
;; Zbc unspecs |
| 82 |
UNSPEC_CLMUL |
| 83 |
UNSPEC_CLMULH |
| 84 |
UNSPEC_CLMULR |
| 85 |
|
| 86 |
;; the calling convention of callee |
| 87 |
UNSPEC_CALLEE_CC |
| 88 |
|
| 89 |
;; String unspecs |
| 90 |
UNSPEC_STRLEN |
| 91 |
|
| 92 |
;; Workaround for HFmode and BFmode without hardware extension |
| 93 |
UNSPEC_FMV_FP16_X |
| 94 |
|
| 95 |
;; XTheadFmv moves |
| 96 |
UNSPEC_XTHEADFMV |
| 97 |
UNSPEC_XTHEADFMV_HW |
| 98 |
|
| 99 |
;; CRC unspecs |
| 100 |
UNSPEC_CRC |
| 101 |
UNSPEC_CRC_REV |
| 102 |
|
| 103 |
;; Stack Smash Protector |
| 104 |
UNSPEC_SSP_SET |
| 105 |
UNSPEC_SSP_TEST |
| 106 |
]) |
| 107 |
|
| 108 |
(define_c_enum "unspecv" [ |
| 109 |
;; Register save and restore. |
| 110 |
UNSPECV_GPR_SAVE |
| 111 |
UNSPECV_GPR_RESTORE |
| 112 |
|
| 113 |
;; Floating-point unspecs. |
| 114 |
UNSPECV_FRCSR |
| 115 |
UNSPECV_FSCSR |
| 116 |
UNSPECV_FRFLAGS |
| 117 |
UNSPECV_FSFLAGS |
| 118 |
UNSPECV_FSNVSNAN |
| 119 |
|
| 120 |
;; Interrupt handler instructions. |
| 121 |
UNSPECV_MRET |
| 122 |
UNSPECV_SRET |
| 123 |
UNSPECV_URET |
| 124 |
|
| 125 |
;; Blockage and synchronization. |
| 126 |
UNSPECV_BLOCKAGE |
| 127 |
UNSPECV_FENCE |
| 128 |
UNSPECV_FENCE_I |
| 129 |
|
| 130 |
;; CMO instructions. |
| 131 |
UNSPECV_CLEAN |
| 132 |
UNSPECV_FLUSH |
| 133 |
UNSPECV_INVAL |
| 134 |
UNSPECV_ZERO |
| 135 |
UNSPECV_PREI |
| 136 |
|
| 137 |
;; Zihintpause unspec |
| 138 |
UNSPECV_PAUSE |
| 139 |
|
| 140 |
;; ZICFISS |
| 141 |
UNSPECV_SSPUSH |
| 142 |
UNSPECV_SSPOPCHK |
| 143 |
UNSPECV_SSRDP |
| 144 |
UNSPECV_SSP |
| 145 |
|
| 146 |
;; ZICFILP |
| 147 |
UNSPECV_LPAD |
| 148 |
UNSPECV_SETLPL |
| 149 |
UNSPECV_LPAD_ALIGN |
| 150 |
UNSPECV_SET_GUARDED |
| 151 |
|
| 152 |
;; XTheadInt unspec |
| 153 |
UNSPECV_XTHEADINT_PUSH |
| 154 |
UNSPECV_XTHEADINT_POP |
| 155 |
]) |
| 156 |
|
| 157 |
(define_constants |
| 158 |
[(RETURN_ADDR_REGNUM 1) |
| 159 |
(SP_REGNUM 2) |
| 160 |
(GP_REGNUM 3) |
| 161 |
(TP_REGNUM 4) |
| 162 |
(T0_REGNUM 5) |
| 163 |
(T1_REGNUM 6) |
| 164 |
(T2_REGNUM 7) |
| 165 |
(S0_REGNUM 8) |
| 166 |
(S1_REGNUM 9) |
| 167 |
(A0_REGNUM 10) |
| 168 |
(A1_REGNUM 11) |
| 169 |
(S2_REGNUM 18) |
| 170 |
(S3_REGNUM 19) |
| 171 |
(S4_REGNUM 20) |
| 172 |
(S5_REGNUM 21) |
| 173 |
(S6_REGNUM 22) |
| 174 |
(S7_REGNUM 23) |
| 175 |
(S8_REGNUM 24) |
| 176 |
(S9_REGNUM 25) |
| 177 |
(S10_REGNUM 26) |
| 178 |
(S11_REGNUM 27) |
| 179 |
|
| 180 |
(NORMAL_RETURN 0) |
| 181 |
(SIBCALL_RETURN 1) |
| 182 |
(EXCEPTION_RETURN 2) |
| 183 |
(VL_REGNUM 66) |
| 184 |
(VTYPE_REGNUM 67) |
| 185 |
(VXRM_REGNUM 68) |
| 186 |
(FRM_REGNUM 69) |
| 187 |
]) |
| 188 |
|
| 189 |
(include "predicates.md") |
| 190 |
(include "constraints.md") |
| 191 |
(include "iterators.md") |
| 192 |
|
| 193 |
;; .................... |
| 194 |
;; |
| 195 |
;; Attributes |
| 196 |
;; |
| 197 |
;; .................... |
| 198 |
|
| 199 |
(define_attr "got" "unset,xgot_high,load" |
| 200 |
(const_string "unset")) |
| 201 |
|
| 202 |
;; Classification of moves, extensions and truncations. Most values |
| 203 |
;; are as for "type" (see below) but there are also the following |
| 204 |
;; move-specific values: |
| 205 |
;; |
| 206 |
;; andi a single ANDI instruction |
| 207 |
;; shift_shift a shift left followed by a shift right |
| 208 |
;; |
| 209 |
;; This attribute is used to determine the instruction's length and |
| 210 |
;; scheduling type. For doubleword moves, the attribute always describes |
| 211 |
;; the split instructions; in some cases, it is more appropriate for the |
| 212 |
;; scheduling type to be "multi" instead. |
| 213 |
(define_attr "move_type" |
| 214 |
"unknown,load,fpload,store,fpstore,mtc,mfc,move,fmove, |
| 215 |
const,logical,arith,andi,shift_shift,rdvlenb" |
| 216 |
(const_string "unknown")) |
| 217 |
|
| 218 |
;; Main data type used by the insn |
| 219 |
(define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,HF,BF,SF,DF,TF, |
| 220 |
RVVMF64BI,RVVMF32BI,RVVMF16BI,RVVMF8BI,RVVMF4BI,RVVMF2BI,RVVM1BI, |
| 221 |
RVVM8QI,RVVM4QI,RVVM2QI,RVVM1QI,RVVMF2QI,RVVMF4QI,RVVMF8QI, |
| 222 |
RVVM8HI,RVVM4HI,RVVM2HI,RVVM1HI,RVVMF2HI,RVVMF4HI, |
| 223 |
RVVM8BF,RVVM4BF,RVVM2BF,RVVM1BF,RVVMF2BF,RVVMF4BF, |
| 224 |
RVVM8HF,RVVM4HF,RVVM2HF,RVVM1HF,RVVMF2HF,RVVMF4HF, |
| 225 |
RVVM8SI,RVVM4SI,RVVM2SI,RVVM1SI,RVVMF2SI, |
| 226 |
RVVM8SF,RVVM4SF,RVVM2SF,RVVM1SF,RVVMF2SF, |
| 227 |
RVVM8DI,RVVM4DI,RVVM2DI,RVVM1DI, |
| 228 |
RVVM8DF,RVVM4DF,RVVM2DF,RVVM1DF, |
| 229 |
RVVM1x8QI,RVVMF2x8QI,RVVMF4x8QI,RVVMF8x8QI, |
| 230 |
RVVM1x7QI,RVVMF2x7QI,RVVMF4x7QI,RVVMF8x7QI, |
| 231 |
RVVM1x6QI,RVVMF2x6QI,RVVMF4x6QI,RVVMF8x6QI, |
| 232 |
RVVM1x5QI,RVVMF2x5QI,RVVMF4x5QI,RVVMF8x5QI, |
| 233 |
RVVM2x4QI,RVVM1x4QI,RVVMF2x4QI,RVVMF4x4QI,RVVMF8x4QI, |
| 234 |
RVVM2x3QI,RVVM1x3QI,RVVMF2x3QI,RVVMF4x3QI,RVVMF8x3QI, |
| 235 |
RVVM4x2QI,RVVM2x2QI,RVVM1x2QI,RVVMF2x2QI,RVVMF4x2QI,RVVMF8x2QI, |
| 236 |
RVVM1x8HI,RVVMF2x8HI,RVVMF4x8HI, |
| 237 |
RVVM1x7HI,RVVMF2x7HI,RVVMF4x7HI, |
| 238 |
RVVM1x6HI,RVVMF2x6HI,RVVMF4x6HI, |
| 239 |
RVVM1x5HI,RVVMF2x5HI,RVVMF4x5HI, |
| 240 |
RVVM2x4HI,RVVM1x4HI,RVVMF2x4HI,RVVMF4x4HI, |
| 241 |
RVVM2x3HI,RVVM1x3HI,RVVMF2x3HI,RVVMF4x3HI, |
| 242 |
RVVM4x2HI,RVVM2x2HI,RVVM1x2HI,RVVMF2x2HI,RVVMF4x2HI, |
| 243 |
RVVM1x8BF,RVVMF2x8BF,RVVMF4x8BF,RVVM1x7BF,RVVMF2x7BF, |
| 244 |
RVVMF4x7BF,RVVM1x6BF,RVVMF2x6BF,RVVMF4x6BF,RVVM1x5BF, |
| 245 |
RVVMF2x5BF,RVVMF4x5BF,RVVM2x4BF,RVVM1x4BF,RVVMF2x4BF, |
| 246 |
RVVMF4x4BF,RVVM2x3BF,RVVM1x3BF,RVVMF2x3BF,RVVMF4x3BF, |
| 247 |
RVVM4x2BF,RVVM2x2BF,RVVM1x2BF,RVVMF2x2BF,RVVMF4x2BF, |
| 248 |
RVVM1x8HF,RVVMF2x8HF,RVVMF4x8HF,RVVM1x7HF,RVVMF2x7HF, |
| 249 |
RVVMF4x7HF,RVVM1x6HF,RVVMF2x6HF,RVVMF4x6HF,RVVM1x5HF, |
| 250 |
RVVMF2x5HF,RVVMF4x5HF,RVVM2x4HF,RVVM1x4HF,RVVMF2x4HF, |
| 251 |
RVVMF4x4HF,RVVM2x3HF,RVVM1x3HF,RVVMF2x3HF,RVVMF4x3HF, |
| 252 |
RVVM4x2HF,RVVM2x2HF,RVVM1x2HF,RVVMF2x2HF,RVVMF4x2HF, |
| 253 |
RVVM1x8SI,RVVMF2x8SI, |
| 254 |
RVVM1x7SI,RVVMF2x7SI, |
| 255 |
RVVM1x6SI,RVVMF2x6SI, |
| 256 |
RVVM1x5SI,RVVMF2x5SI, |
| 257 |
RVVM2x4SI,RVVM1x4SI,RVVMF2x4SI, |
| 258 |
RVVM2x3SI,RVVM1x3SI,RVVMF2x3SI, |
| 259 |
RVVM4x2SI,RVVM2x2SI,RVVM1x2SI,RVVMF2x2SI, |
| 260 |
RVVM1x8SF,RVVMF2x8SF,RVVM1x7SF,RVVMF2x7SF, |
| 261 |
RVVM1x6SF,RVVMF2x6SF,RVVM1x5SF,RVVMF2x5SF, |
| 262 |
RVVM2x4SF,RVVM1x4SF,RVVMF2x4SF,RVVM2x3SF, |
| 263 |
RVVM1x3SF,RVVMF2x3SF,RVVM4x2SF,RVVM2x2SF, |
| 264 |
RVVM1x2SF,RVVMF2x2SF, |
| 265 |
RVVM1x8DI,RVVM1x7DI,RVVM1x6DI,RVVM1x5DI, |
| 266 |
RVVM2x4DI,RVVM1x4DI,RVVM2x3DI,RVVM1x3DI, |
| 267 |
RVVM4x2DI,RVVM2x2DI,RVVM1x2DI,RVVM1x8DF, |
| 268 |
RVVM1x7DF,RVVM1x6DF,RVVM1x5DF,RVVM2x4DF, |
| 269 |
RVVM1x4DF,RVVM2x3DF,RVVM1x3DF,RVVM4x2DF, |
| 270 |
RVVM2x2DF,RVVM1x2DF, |
| 271 |
V1QI,V2QI,V4QI,V8QI,V16QI,V32QI,V64QI,V128QI,V256QI,V512QI,V1024QI,V2048QI,V4096QI, |
| 272 |
V1HI,V2HI,V4HI,V8HI,V16HI,V32HI,V64HI,V128HI,V256HI,V512HI,V1024HI,V2048HI, |
| 273 |
V1SI,V2SI,V4SI,V8SI,V16SI,V32SI,V64SI,V128SI,V256SI,V512SI,V1024SI, |
| 274 |
V1DI,V2DI,V4DI,V8DI,V16DI,V32DI,V64DI,V128DI,V256DI,V512DI, |
| 275 |
V1HF,V2HF,V4HF,V8HF,V16HF,V32HF,V64HF,V128HF,V256HF,V512HF,V1024HF,V2048HF, |
| 276 |
V1SF,V2SF,V4SF,V8SF,V16SF,V32SF,V64SF,V128SF,V256SF,V512SF,V1024SF, |
| 277 |
V1DF,V2DF,V4DF,V8DF,V16DF,V32DF,V64DF,V128DF,V256DF,V512DF, |
| 278 |
V1BI,V2BI,V4BI,V8BI,V16BI,V32BI,V64BI,V128BI,V256BI,V512BI,V1024BI,V2048BI,V4096BI" |
| 279 |
(const_string "unknown")) |
| 280 |
|
| 281 |
;; True if the main data type is twice the size of a word. |
| 282 |
(define_attr "dword_mode" "no,yes" |
| 283 |
(cond [(and (eq_attr "mode" "DI,DF") |
| 284 |
(eq (symbol_ref "TARGET_64BIT") (const_int 0))) |
| 285 |
(const_string "yes") |
| 286 |
|
| 287 |
(and (eq_attr "mode" "TI,TF") |
| 288 |
(ne (symbol_ref "TARGET_64BIT") (const_int 0))) |
| 289 |
(const_string "yes")] |
| 290 |
(const_string "no"))) |
| 291 |
|
| 292 |
;; ISA attributes. |
| 293 |
(define_attr "ext" "base,f,d,vector" |
| 294 |
(const_string "base")) |
| 295 |
|
| 296 |
;; True if the extension is enabled. |
| 297 |
(define_attr "ext_enabled" "no,yes" |
| 298 |
(cond [(eq_attr "ext" "base") |
| 299 |
(const_string "yes") |
| 300 |
|
| 301 |
(and (eq_attr "ext" "f") |
| 302 |
(match_test "TARGET_HARD_FLOAT")) |
| 303 |
(const_string "yes") |
| 304 |
|
| 305 |
(and (eq_attr "ext" "d") |
| 306 |
(match_test "TARGET_DOUBLE_FLOAT")) |
| 307 |
(const_string "yes") |
| 308 |
|
| 309 |
(and (eq_attr "ext" "vector") |
| 310 |
(match_test "TARGET_VECTOR")) |
| 311 |
(const_string "yes") |
| 312 |
] |
| 313 |
(const_string "no"))) |
| 314 |
|
| 315 |
;; Classification of each insn. |
| 316 |
;; branch conditional branch |
| 317 |
;; jump unconditional direct jump |
| 318 |
;; jalr unconditional indirect jump |
| 319 |
;; ret various returns, no arguments |
| 320 |
;; call unconditional call |
| 321 |
;; load load instruction(s) |
| 322 |
;; fpload floating point load |
| 323 |
;; store store instruction(s) |
| 324 |
;; fpstore floating point store |
| 325 |
;; mtc transfer to coprocessor |
| 326 |
;; mfc transfer from coprocessor |
| 327 |
;; const load constant |
| 328 |
;; arith integer arithmetic instructions |
| 329 |
;; logical integer logical instructions |
| 330 |
;; shift integer shift instructions |
| 331 |
;; slt set less than instructions |
| 332 |
;; imul integer multiply |
| 333 |
;; idiv integer divide |
| 334 |
;; move integer register move (addi rd, rs1, 0) |
| 335 |
;; fmove floating point register move |
| 336 |
;; fadd floating point add/subtract |
| 337 |
;; fmul floating point multiply |
| 338 |
;; fmadd floating point multiply-add |
| 339 |
;; fdiv floating point divide |
| 340 |
;; fcmp floating point compare |
| 341 |
;; fcvt floating point convert |
| 342 |
;; fcvt_i2f integer to floating point convert |
| 343 |
;; fcvt_f2i floating point to integer convert |
| 344 |
;; fsqrt floating point square root |
| 345 |
;; multi multiword sequence (or user asm statements) |
| 346 |
;; auipc integer addition to PC |
| 347 |
;; sfb_alu SFB ALU instruction |
| 348 |
;; nop no operation |
| 349 |
;; trap trap instruction |
| 350 |
;; ghost an instruction that produces no real code |
| 351 |
;; bitmanip bit manipulation instructions |
| 352 |
;; clmul clmul, clmulh, clmulr |
| 353 |
;; rotate rotation instructions |
| 354 |
;; atomic atomic instructions |
| 355 |
;; condmove conditional moves |
| 356 |
;; crypto cryptography instructions |
| 357 |
;; mvpair zc move pair instructions |
| 358 |
;; zicond zicond instructions |
| 359 |
;; Classification of RVV instructions which will be added to each RVV .md pattern and used by scheduler. |
| 360 |
;; rdvlenb vector byte length vlenb csrr read |
| 361 |
;; rdvl vector length vl csrr read |
| 362 |
;; wrvxrm vector fixed-point rounding mode write |
| 363 |
;; wrfrm vector floating-point rounding mode write |
| 364 |
;; vsetvl vector configuration-setting instrucions |
| 365 |
;; 7. Vector Loads and Stores |
| 366 |
;; vlde vector unit-stride load instructions |
| 367 |
;; vste vector unit-stride store instructions |
| 368 |
;; vldm vector unit-stride mask load instructions |
| 369 |
;; vstm vector unit-stride mask store instructions |
| 370 |
;; vlds vector strided load instructions |
| 371 |
;; vsts vector strided store instructions |
| 372 |
;; vldux vector unordered indexed load instructions |
| 373 |
;; vldox vector ordered indexed load instructions |
| 374 |
;; vstux vector unordered indexed store instructions |
| 375 |
;; vstox vector ordered indexed store instructions |
| 376 |
;; vldff vector unit-stride fault-only-first load instructions |
| 377 |
;; vldr vector whole register load instructions |
| 378 |
;; vstr vector whole register store instructions |
| 379 |
;; vlsegde vector segment unit-stride load instructions |
| 380 |
;; vssegte vector segment unit-stride store instructions |
| 381 |
;; vlsegds vector segment strided load instructions |
| 382 |
;; vssegts vector segment strided store instructions |
| 383 |
;; vlsegdux vector segment unordered indexed load instructions |
| 384 |
;; vlsegdox vector segment ordered indexed load instructions |
| 385 |
;; vssegtux vector segment unordered indexed store instructions |
| 386 |
;; vssegtox vector segment ordered indexed store instructions |
| 387 |
;; vlsegdff vector segment unit-stride fault-only-first load instructions |
| 388 |
;; 11. Vector integer arithmetic instructions |
| 389 |
;; vialu vector single-width integer add and subtract and logical nstructions |
| 390 |
;; viwalu vector widening integer add/subtract |
| 391 |
;; vext vector integer extension |
| 392 |
;; vicalu vector arithmetic with carry or borrow instructions |
| 393 |
;; vshift vector single-width bit shift instructions |
| 394 |
;; vnshift vector narrowing integer shift instructions |
| 395 |
;; viminmax vector integer min/max instructions |
| 396 |
;; vicmp vector integer comparison instructions |
| 397 |
;; vimul vector single-width integer multiply instructions |
| 398 |
;; vidiv vector single-width integer divide instructions |
| 399 |
;; viwmul vector widening integer multiply instructions |
| 400 |
;; vimuladd vector single-width integer multiply-add instructions |
| 401 |
;; viwmuladd vector widening integer multiply-add instructions |
| 402 |
;; vimerge vector integer merge instructions |
| 403 |
;; vimov vector integer move vector instructions |
| 404 |
;; 12. Vector fixed-point arithmetic instructions |
| 405 |
;; vsalu vector single-width saturating add and subtract and logical instructions |
| 406 |
;; vaalu vector single-width averaging add and subtract and logical instructions |
| 407 |
;; vsmul vector single-width fractional multiply with rounding and saturation instructions |
| 408 |
;; vsshift vector single-width scaling shift instructions |
| 409 |
;; vnclip vector narrowing fixed-point clip instructions |
| 410 |
;; 13. Vector floating-point instructions |
| 411 |
;; vfalu vector single-width floating-point add/subtract instructions |
| 412 |
;; vfwalu vector widening floating-point add/subtract instructions |
| 413 |
;; vfmul vector single-width floating-point multiply instructions |
| 414 |
;; vfdiv vector single-width floating-point divide instructions |
| 415 |
;; vfwmul vector widening floating-point multiply instructions |
| 416 |
;; vfmuladd vector single-width floating-point multiply-add instructions |
| 417 |
;; vfwmuladd vector widening floating-point multiply-add instructions |
| 418 |
;; vfsqrt vector floating-point square-root instructions |
| 419 |
;; vfrecp vector floating-point reciprocal square-root instructions |
| 420 |
;; vfminmax vector floating-point min/max instructions |
| 421 |
;; vfcmp vector floating-point comparison instructions |
| 422 |
;; vfsgnj vector floating-point sign-injection instructions |
| 423 |
;; vfclass vector floating-point classify instruction |
| 424 |
;; vfmerge vector floating-point merge instruction |
| 425 |
;; vfmov vector floating-point move instruction |
| 426 |
;; vfcvtitof vector single-width integer to floating-point instruction |
| 427 |
;; vfcvtftoi vector single-width floating-point to integer instruction |
| 428 |
;; vfwcvtitof vector widening integer to floating-point instruction |
| 429 |
;; vfwcvtftoi vector widening floating-point to integer instruction |
| 430 |
;; vfwcvtftof vector widening floating-point to floating-point instruction |
| 431 |
;; vfncvtitof vector narrowing integer to floating-point instruction |
| 432 |
;; vfncvtftoi vector narrowing floating-point to integer instruction |
| 433 |
;; vfncvtftof vector narrowing floating-point to floating-point instruction |
| 434 |
;; 14. Vector reduction operations |
| 435 |
;; vired vector single-width integer reduction instructions |
| 436 |
;; viwred vector widening integer reduction instructions |
| 437 |
;; vfredu vector single-width floating-point un-ordered reduction instruction |
| 438 |
;; vfredo vector single-width floating-point ordered reduction instruction |
| 439 |
;; vfwredu vector widening floating-point un-ordered reduction instruction |
| 440 |
;; vfwredo vector widening floating-point ordered reduction instruction |
| 441 |
;; 15. Vector mask instructions |
| 442 |
;; vmalu vector mask-register logical instructions |
| 443 |
;; vmpop vector mask population count |
| 444 |
;; vmffs vector find-first-set mask bit |
| 445 |
;; vmsfs vector set mask bit |
| 446 |
;; vmiota vector iota |
| 447 |
;; vmidx vector element index instruction |
| 448 |
;; 16. Vector permutation instructions |
| 449 |
;; vimovvx integer scalar move instructions |
| 450 |
;; vimovxv integer scalar move instructions |
| 451 |
;; vfmovvf floating-point scalar move instructions |
| 452 |
;; vfmovfv floating-point scalar move instructions |
| 453 |
;; vslideup vector slide instructions |
| 454 |
;; vslidedown vector slide instructions |
| 455 |
;; vislide1up vector slide instructions |
| 456 |
;; vislide1down vector slide instructions |
| 457 |
;; vfslide1up vector slide instructions |
| 458 |
;; vfslide1down vector slide instructions |
| 459 |
;; vgather vector register gather instructions |
| 460 |
;; vcompress vector compress instruction |
| 461 |
;; vmov whole vector register move |
| 462 |
;; vector unknown vector instruction |
| 463 |
;; 17. Crypto Vector instructions |
| 464 |
;; vandn crypto vector bitwise and-not instructions |
| 465 |
;; vbrev crypto vector reverse bits in elements instructions |
| 466 |
;; vbrev8 crypto vector reverse bits in bytes instructions |
| 467 |
;; vrev8 crypto vector reverse bytes instructions |
| 468 |
;; vclz crypto vector count leading Zeros instructions |
| 469 |
;; vctz crypto vector count lrailing Zeros instructions |
| 470 |
;; vrol crypto vector rotate left instructions |
| 471 |
;; vror crypto vector rotate right instructions |
| 472 |
;; vwsll crypto vector widening shift left logical instructions |
| 473 |
;; vclmul crypto vector carry-less multiply - return low half instructions |
| 474 |
;; vclmulh crypto vector carry-less multiply - return high half instructions |
| 475 |
;; vghsh crypto vector add-multiply over GHASH Galois-Field instructions |
| 476 |
;; vgmul crypto vector multiply over GHASH Galois-Field instrumctions |
| 477 |
;; vaesef crypto vector AES final-round encryption instructions |
| 478 |
;; vaesem crypto vector AES middle-round encryption instructions |
| 479 |
;; vaesdf crypto vector AES final-round decryption instructions |
| 480 |
;; vaesdm crypto vector AES middle-round decryption instructions |
| 481 |
;; vaeskf1 crypto vector AES-128 Forward KeySchedule generation instructions |
| 482 |
;; vaeskf2 crypto vector AES-256 Forward KeySchedule generation instructions |
| 483 |
;; vaesz crypto vector AES round zero encryption/decryption instructions |
| 484 |
;; vsha2ms crypto vector SHA-2 message schedule instructions |
| 485 |
;; vsha2ch crypto vector SHA-2 two rounds of compression instructions |
| 486 |
;; vsha2cl crypto vector SHA-2 two rounds of compression instructions |
| 487 |
;; vsm4k crypto vector SM4 KeyExpansion instructions |
| 488 |
;; vsm4r crypto vector SM4 Rounds instructions |
| 489 |
;; vsm3me crypto vector SM3 Message Expansion instructions |
| 490 |
;; vsm3c crypto vector SM3 Compression instructions |
| 491 |
;; 18.Vector BF16 instrctions |
| 492 |
;; vfncvtbf16 vector narrowing single floating-point to brain floating-point instruction |
| 493 |
;; vfwcvtbf16 vector widening brain floating-point to single floating-point instruction |
| 494 |
;; vfwmaccbf16 vector BF16 widening multiply-accumulate |
| 495 |
;; SiFive custom extension instrctions |
| 496 |
;; sf_vqmacc vector matrix integer multiply-add instructions |
| 497 |
;; sf_vfnrclip vector fp32 to int8 ranged clip instructions |
| 498 |
(define_attr "type" |
| 499 |
"unknown,branch,jump,jalr,ret,call,load,fpload,store,fpstore, |
| 500 |
mtc,mfc,const,arith,logical,shift,slt,imul,idiv,move,fmove,fadd,fmul, |
| 501 |
fmadd,fdiv,fcmp,fcvt,fcvt_i2f,fcvt_f2i,fsqrt,multi,auipc,sfb_alu,nop,trap, |
| 502 |
ghost,bitmanip,rotate,clmul,min,max,minu,maxu,clz,ctz,cpop, |
| 503 |
atomic,condmove,crypto,mvpair,zicond,rdvlenb,rdvl,wrvxrm,wrfrm, |
| 504 |
rdfrm,vsetvl,vsetvl_pre,vlde,vste,vldm,vstm,vlds,vsts, |
| 505 |
vldux,vldox,vstux,vstox,vldff,vldr,vstr, |
| 506 |
vlsegde,vssegte,vlsegds,vssegts,vlsegdux,vlsegdox,vssegtux,vssegtox,vlsegdff, |
| 507 |
vialu,viwalu,vext,vicalu,vshift,vnshift,vicmp,viminmax, |
| 508 |
vimul,vidiv,viwmul,vimuladd,sf_vqmacc,viwmuladd,vimerge,vimov, |
| 509 |
vsalu,vaalu,vsmul,vsshift,vnclip,sf_vfnrclip, |
| 510 |
vfalu,vfwalu,vfmul,vfdiv,vfwmul,vfmuladd,vfwmuladd,vfsqrt,vfrecp, |
| 511 |
vfcmp,vfminmax,vfsgnj,vfclass,vfmerge,vfmov, |
| 512 |
vfcvtitof,vfcvtftoi,vfwcvtitof,vfwcvtftoi, |
| 513 |
vfwcvtftof,vfncvtitof,vfncvtftoi,vfncvtftof, |
| 514 |
vired,viwred,vfredu,vfredo,vfwredu,vfwredo, |
| 515 |
vmalu,vmpop,vmffs,vmsfs,vmiota,vmidx,vimovvx,vimovxv,vfmovvf,vfmovfv, |
| 516 |
vslideup,vslidedown,vislide1up,vislide1down,vfslide1up,vfslide1down, |
| 517 |
vgather,vcompress,vmov,vector,vandn,vbrev,vbrev8,vrev8,vclz,vctz,vcpop,vrol,vror,vwsll, |
| 518 |
vclmul,vclmulh,vghsh,vgmul,vaesef,vaesem,vaesdf,vaesdm,vaeskf1,vaeskf2,vaesz, |
| 519 |
vsha2ms,vsha2ch,vsha2cl,vsm4k,vsm4r,vsm3me,vsm3c,vfncvtbf16,vfwcvtbf16,vfwmaccbf16" |
| 520 |
(cond [(eq_attr "got" "load") (const_string "load") |
| 521 |
|
| 522 |
;; If a doubleword move uses these expensive instructions, |
| 523 |
;; it is usually better to schedule them in the same way |
| 524 |
;; as the singleword form, rather than as "multi". |
| 525 |
(eq_attr "move_type" "load") (const_string "load") |
| 526 |
(eq_attr "move_type" "fpload") (const_string "fpload") |
| 527 |
(eq_attr "move_type" "store") (const_string "store") |
| 528 |
(eq_attr "move_type" "fpstore") (const_string "fpstore") |
| 529 |
(eq_attr "move_type" "mtc") (const_string "mtc") |
| 530 |
(eq_attr "move_type" "mfc") (const_string "mfc") |
| 531 |
|
| 532 |
;; These types of move are always single insns. |
| 533 |
(eq_attr "move_type" "fmove") (const_string "fmove") |
| 534 |
(eq_attr "move_type" "arith") (const_string "arith") |
| 535 |
(eq_attr "move_type" "logical") (const_string "logical") |
| 536 |
(eq_attr "move_type" "andi") (const_string "logical") |
| 537 |
|
| 538 |
;; These types of move are always split. |
| 539 |
(eq_attr "move_type" "shift_shift") |
| 540 |
(const_string "multi") |
| 541 |
|
| 542 |
;; These types of move are split for doubleword modes only. |
| 543 |
(and (eq_attr "move_type" "move,const") |
| 544 |
(eq_attr "dword_mode" "yes")) |
| 545 |
(const_string "multi") |
| 546 |
(eq_attr "move_type" "move") (const_string "move") |
| 547 |
(eq_attr "move_type" "const") (const_string "const") |
| 548 |
(eq_attr "move_type" "rdvlenb") (const_string "rdvlenb")] |
| 549 |
(const_string "unknown"))) |
| 550 |
|
| 551 |
;; True if the float point vector is disabled. |
| 552 |
(define_attr "fp_vector_disabled" "no,yes" |
| 553 |
(cond [ |
| 554 |
(and (eq_attr "type" "vfmov,vfalu,vfmul,vfdiv, |
| 555 |
vfwalu,vfwmul,vfmuladd,vfwmuladd, |
| 556 |
vfsqrt,vfrecp,vfminmax,vfsgnj,vfcmp, |
| 557 |
vfclass,vfmerge, |
| 558 |
vfncvtitof,vfwcvtftoi,vfcvtftoi,vfcvtitof, |
| 559 |
vfredo,vfredu,vfwredo,vfwredu, |
| 560 |
vfslide1up,vfslide1down") |
| 561 |
(and (eq_attr "mode" "RVVM8HF,RVVM4HF,RVVM2HF,RVVM1HF,RVVMF2HF,RVVMF4HF") |
| 562 |
(match_test "!TARGET_ZVFH"))) |
| 563 |
(const_string "yes") |
| 564 |
|
| 565 |
;; The mode records as QI for the FP16 <=> INT8 instruction. |
| 566 |
(and (eq_attr "type" "vfncvtftoi,vfwcvtitof") |
| 567 |
(and (eq_attr "mode" "RVVM4QI,RVVM2QI,RVVM1QI,RVVMF2QI,RVVMF4QI,RVVMF8QI") |
| 568 |
(match_test "!TARGET_ZVFH"))) |
| 569 |
(const_string "yes") |
| 570 |
] |
| 571 |
(const_string "no"))) |
| 572 |
|
| 573 |
;; This attribute marks the alternatives not matching the constraints |
| 574 |
;; described in spec as disabled. |
| 575 |
(define_attr "spec_restriction" "none,thv,rvv" |
| 576 |
(const_string "none")) |
| 577 |
|
| 578 |
(define_attr "spec_restriction_disabled" "no,yes" |
| 579 |
(cond [(eq_attr "spec_restriction" "none") |
| 580 |
(const_string "no") |
| 581 |
|
| 582 |
(and (eq_attr "spec_restriction" "thv") |
| 583 |
(match_test "TARGET_XTHEADVECTOR")) |
| 584 |
(const_string "yes") |
| 585 |
|
| 586 |
(and (eq_attr "spec_restriction" "rvv") |
| 587 |
(match_test "TARGET_VECTOR && !TARGET_XTHEADVECTOR")) |
| 588 |
(const_string "yes") |
| 589 |
] |
| 590 |
(const_string "no"))) |
| 591 |
|
| 592 |
;; Attribute to control enable or disable instructions. |
| 593 |
(define_attr "enabled" "no,yes" |
| 594 |
(cond [ |
| 595 |
(eq_attr "ext_enabled" "no") |
| 596 |
(const_string "no") |
| 597 |
|
| 598 |
(eq_attr "fp_vector_disabled" "yes") |
| 599 |
(const_string "no") |
| 600 |
|
| 601 |
(eq_attr "spec_restriction_disabled" "yes") |
| 602 |
(const_string "no") |
| 603 |
] |
| 604 |
(const_string "yes"))) |
| 605 |
|
| 606 |
;; Length of instruction in bytes. |
| 607 |
(define_attr "length" "" |
| 608 |
(cond [ |
| 609 |
;; Branches further than +/- 1 MiB require three instructions. |
| 610 |
;; Branches further than +/- 4 KiB require two instructions. |
| 611 |
(eq_attr "type" "branch") |
| 612 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 613 |
(const_int 4088)) |
| 614 |
(le (minus (pc) (match_dup 0)) |
| 615 |
(const_int 4092))) |
| 616 |
(const_int 4) |
| 617 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 618 |
(const_int 1048568)) |
| 619 |
(le (minus (pc) (match_dup 0)) |
| 620 |
(const_int 1048572))) |
| 621 |
(const_int 8) |
| 622 |
(const_int 12))) |
| 623 |
|
| 624 |
;; Jumps further than +/- 1 MiB require two instructions. |
| 625 |
(eq_attr "type" "jump") |
| 626 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 627 |
(const_int 1048568)) |
| 628 |
(le (minus (pc) (match_dup 0)) |
| 629 |
(const_int 1048572))) |
| 630 |
(const_int 4) |
| 631 |
(const_int 8)) |
| 632 |
|
| 633 |
;; Conservatively assume calls take two instructions (AUIPC + JALR). |
| 634 |
;; The linker will opportunistically relax the sequence to JAL. |
| 635 |
(eq_attr "type" "call") (const_int 8) |
| 636 |
|
| 637 |
;; "Ghost" instructions occupy no space. |
| 638 |
(eq_attr "type" "ghost") (const_int 0) |
| 639 |
|
| 640 |
(eq_attr "got" "load") (const_int 8) |
| 641 |
|
| 642 |
;; SHIFT_SHIFTs are decomposed into two separate instructions. |
| 643 |
(eq_attr "move_type" "shift_shift") |
| 644 |
(const_int 8) |
| 645 |
|
| 646 |
;; Check for doubleword moves that are decomposed into two |
| 647 |
;; instructions. |
| 648 |
(and (eq_attr "move_type" "mtc,mfc,move") |
| 649 |
(eq_attr "dword_mode" "yes")) |
| 650 |
(const_int 8) |
| 651 |
|
| 652 |
;; Doubleword CONST{,N} moves are split into two word |
| 653 |
;; CONST{,N} moves. |
| 654 |
(and (eq_attr "move_type" "const") |
| 655 |
(eq_attr "dword_mode" "yes")) |
| 656 |
(symbol_ref "riscv_split_const_insns (operands[1]) * 4") |
| 657 |
|
| 658 |
;; Otherwise, constants, loads and stores are handled by external |
| 659 |
;; routines. |
| 660 |
(eq_attr "move_type" "load,fpload") |
| 661 |
(symbol_ref "riscv_load_store_insns (operands[1], insn) * 4") |
| 662 |
(eq_attr "move_type" "store,fpstore") |
| 663 |
(symbol_ref "riscv_load_store_insns (operands[0], insn) * 4") |
| 664 |
] (const_int 4))) |
| 665 |
|
| 666 |
;; Is copying of this instruction disallowed? |
| 667 |
(define_attr "cannot_copy" "no,yes" (const_string "no")) |
| 668 |
|
| 669 |
;; Microarchitectures we know how to tune for. |
| 670 |
;; Keep this in sync with enum riscv_microarchitecture. |
| 671 |
(define_attr "tune" |
| 672 |
"generic,sifive_7,sifive_p400,sifive_p600,xiangshan,generic_ooo" |
| 673 |
(const (symbol_ref "((enum attr_tune) riscv_microarchitecture)"))) |
| 674 |
|
| 675 |
;; Describe a user's asm statement. |
| 676 |
(define_asm_attributes |
| 677 |
[(set_attr "type" "multi")]) |
| 678 |
|
| 679 |
;; Ghost instructions produce no real code and introduce no hazards. |
| 680 |
;; They exist purely to express an effect on dataflow. |
| 681 |
(define_insn_reservation "ghost" 0 |
| 682 |
(eq_attr "type" "ghost") |
| 683 |
"nothing") |
| 684 |
|
| 685 |
;; |
| 686 |
;; .................... |
| 687 |
;; |
| 688 |
;; ADDITION |
| 689 |
;; |
| 690 |
;; .................... |
| 691 |
;; |
| 692 |
|
| 693 |
(define_insn "add<mode>3" |
| 694 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 695 |
(plus:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 696 |
(match_operand:ANYF 2 "register_operand" " f")))] |
| 697 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 698 |
"fadd.<fmt>\t%0,%1,%2" |
| 699 |
[(set_attr "type" "fadd") |
| 700 |
(set_attr "mode" "<UNITMODE>")]) |
| 701 |
|
| 702 |
(define_insn "*addsi3" |
| 703 |
[(set (match_operand:SI 0 "register_operand" "=r,r") |
| 704 |
(plus:SI (match_operand:SI 1 "register_operand" " r,r") |
| 705 |
(match_operand:SI 2 "arith_operand" " r,I")))] |
| 706 |
"" |
| 707 |
"add%i2%~\t%0,%1,%2" |
| 708 |
[(set_attr "type" "arith") |
| 709 |
(set_attr "mode" "SI")]) |
| 710 |
|
| 711 |
(define_expand "addsi3" |
| 712 |
[(set (match_operand:SI 0 "register_operand" "=r,r") |
| 713 |
(plus:SI (match_operand:SI 1 "register_operand" " r,r") |
| 714 |
(match_operand:SI 2 "arith_operand" " r,I")))] |
| 715 |
"" |
| 716 |
{ |
| 717 |
if (TARGET_64BIT) |
| 718 |
{ |
| 719 |
rtx t = gen_reg_rtx (DImode); |
| 720 |
emit_insn (gen_addsi3_extended (t, operands[1], operands[2])); |
| 721 |
t = gen_lowpart (SImode, t); |
| 722 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 723 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 724 |
emit_move_insn (operands[0], t); |
| 725 |
DONE; |
| 726 |
} |
| 727 |
}) |
| 728 |
|
| 729 |
(define_insn "adddi3" |
| 730 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 731 |
(plus:DI (match_operand:DI 1 "register_operand" " r,r") |
| 732 |
(match_operand:DI 2 "arith_operand" " r,I")))] |
| 733 |
"TARGET_64BIT" |
| 734 |
"add%i2\t%0,%1,%2" |
| 735 |
[(set_attr "type" "arith") |
| 736 |
(set_attr "mode" "DI")]) |
| 737 |
|
| 738 |
;; Special case of adding a reg and constant if latter is sum of two S12 |
| 739 |
;; values (in range -2048 to 2047). Avoid materialized the const and fuse |
| 740 |
;; into the add (with an additional add for 2nd value). Makes a 3 insn |
| 741 |
;; sequence into 2 insn. |
| 742 |
|
| 743 |
(define_insn_and_split "*add<mode>3_const_sum_of_two_s12" |
| 744 |
[(set (match_operand:P 0 "register_operand" "=r,r") |
| 745 |
(plus:P (match_operand:P 1 "register_operand" " r,r") |
| 746 |
(match_operand:P 2 "const_two_s12" " MiG,r")))] |
| 747 |
"!riscv_reg_frame_related (operands[0])" |
| 748 |
{ |
| 749 |
/* operand matching MiG constraint is always meant to be split. */ |
| 750 |
if (which_alternative == 0) |
| 751 |
return "#"; |
| 752 |
else |
| 753 |
return "add %0,%1,%2"; |
| 754 |
} |
| 755 |
"" |
| 756 |
[(set (match_dup 0) |
| 757 |
(plus:P (match_dup 1) (match_dup 3))) |
| 758 |
(set (match_dup 0) |
| 759 |
(plus:P (match_dup 0) (match_dup 4)))] |
| 760 |
{ |
| 761 |
int val = INTVAL (operands[2]); |
| 762 |
if (SUM_OF_TWO_S12_P (val)) |
| 763 |
{ |
| 764 |
operands[3] = GEN_INT (2047); |
| 765 |
operands[4] = GEN_INT (val - 2047); |
| 766 |
} |
| 767 |
else if (SUM_OF_TWO_S12_N (val)) |
| 768 |
{ |
| 769 |
operands[3] = GEN_INT (-2048); |
| 770 |
operands[4] = GEN_INT (val + 2048); |
| 771 |
} |
| 772 |
else |
| 773 |
gcc_unreachable (); |
| 774 |
} |
| 775 |
[(set_attr "type" "arith") |
| 776 |
(set_attr "mode" "<P:MODE>")]) |
| 777 |
|
| 778 |
(define_expand "addv<mode>4" |
| 779 |
[(set (match_operand:GPR 0 "register_operand" "=r,r") |
| 780 |
(plus:GPR (match_operand:GPR 1 "register_operand" " r,r") |
| 781 |
(match_operand:GPR 2 "arith_operand" " r,I"))) |
| 782 |
(label_ref (match_operand 3 "" ""))] |
| 783 |
"" |
| 784 |
{ |
| 785 |
if (TARGET_64BIT && <MODE>mode == SImode) |
| 786 |
{ |
| 787 |
rtx t3 = gen_reg_rtx (DImode); |
| 788 |
rtx t4 = gen_reg_rtx (DImode); |
| 789 |
rtx t5 = gen_reg_rtx (DImode); |
| 790 |
rtx t6 = gen_reg_rtx (DImode); |
| 791 |
|
| 792 |
riscv_emit_binary (PLUS, operands[0], operands[1], operands[2]); |
| 793 |
if (GET_CODE (operands[1]) != CONST_INT) |
| 794 |
emit_insn (gen_extend_insn (t4, operands[1], DImode, SImode, 0)); |
| 795 |
else |
| 796 |
t4 = operands[1]; |
| 797 |
if (GET_CODE (operands[2]) != CONST_INT) |
| 798 |
emit_insn (gen_extend_insn (t5, operands[2], DImode, SImode, 0)); |
| 799 |
else |
| 800 |
t5 = operands[2]; |
| 801 |
emit_insn (gen_adddi3 (t3, t4, t5)); |
| 802 |
emit_insn (gen_extend_insn (t6, operands[0], DImode, SImode, 0)); |
| 803 |
|
| 804 |
riscv_expand_conditional_branch (operands[3], NE, t6, t3); |
| 805 |
} |
| 806 |
else |
| 807 |
{ |
| 808 |
rtx t3 = gen_reg_rtx (<MODE>mode); |
| 809 |
rtx t4 = gen_reg_rtx (<MODE>mode); |
| 810 |
|
| 811 |
emit_insn (gen_add3_insn (operands[0], operands[1], operands[2])); |
| 812 |
rtx cmp1 = gen_rtx_LT (<MODE>mode, operands[2], const0_rtx); |
| 813 |
emit_insn (gen_cstore<mode>4 (t3, cmp1, operands[2], const0_rtx)); |
| 814 |
rtx cmp2 = gen_rtx_LT (<MODE>mode, operands[0], operands[1]); |
| 815 |
|
| 816 |
emit_insn (gen_cstore<mode>4 (t4, cmp2, operands[0], operands[1])); |
| 817 |
riscv_expand_conditional_branch (operands[3], NE, t3, t4); |
| 818 |
} |
| 819 |
DONE; |
| 820 |
}) |
| 821 |
|
| 822 |
(define_expand "uaddv<mode>4" |
| 823 |
[(set (match_operand:GPR 0 "register_operand" "=r,r") |
| 824 |
(plus:GPR (match_operand:GPR 1 "register_operand" " r,r") |
| 825 |
(match_operand:GPR 2 "arith_operand" " r,I"))) |
| 826 |
(label_ref (match_operand 3 "" ""))] |
| 827 |
"" |
| 828 |
{ |
| 829 |
if (TARGET_64BIT && <MODE>mode == SImode) |
| 830 |
{ |
| 831 |
rtx t3 = gen_reg_rtx (DImode); |
| 832 |
rtx t4 = gen_reg_rtx (DImode); |
| 833 |
|
| 834 |
if (GET_CODE (operands[1]) != CONST_INT) |
| 835 |
emit_insn (gen_extend_insn (t3, operands[1], DImode, SImode, 0)); |
| 836 |
else |
| 837 |
t3 = operands[1]; |
| 838 |
riscv_emit_binary (PLUS, operands[0], operands[1], operands[2]); |
| 839 |
emit_insn (gen_extend_insn (t4, operands[0], DImode, SImode, 0)); |
| 840 |
|
| 841 |
riscv_expand_conditional_branch (operands[3], LTU, t4, t3); |
| 842 |
} |
| 843 |
else |
| 844 |
{ |
| 845 |
emit_insn (gen_add3_insn (operands[0], operands[1], operands[2])); |
| 846 |
riscv_expand_conditional_branch (operands[3], LTU, operands[0], |
| 847 |
operands[1]); |
| 848 |
} |
| 849 |
|
| 850 |
DONE; |
| 851 |
}) |
| 852 |
|
| 853 |
(define_insn "addsi3_extended" |
| 854 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 855 |
(sign_extend:DI |
| 856 |
(plus:SI (match_operand:SI 1 "register_operand" " r,r") |
| 857 |
(match_operand:SI 2 "arith_operand" " r,I"))))] |
| 858 |
"TARGET_64BIT" |
| 859 |
"add%i2w\t%0,%1,%2" |
| 860 |
[(set_attr "type" "arith") |
| 861 |
(set_attr "mode" "SI")]) |
| 862 |
|
| 863 |
(define_insn "*addsi3_extended2" |
| 864 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 865 |
(sign_extend:DI |
| 866 |
(match_operator:SI 3 "subreg_lowpart_operator" |
| 867 |
[(plus:DI (match_operand:DI 1 "register_operand" " r,r") |
| 868 |
(match_operand:DI 2 "arith_operand" " r,I"))])))] |
| 869 |
"TARGET_64BIT" |
| 870 |
"add%i2w\t%0,%1,%2" |
| 871 |
[(set_attr "type" "arith") |
| 872 |
(set_attr "mode" "SI")]) |
| 873 |
|
| 874 |
;; Transform (X & C1) + C2 into (X | ~C1) - (-C2 | ~C1) |
| 875 |
;; Where C1 is not a LUI operand, but ~C1 is a LUI operand |
| 876 |
|
| 877 |
(define_insn_and_split "*lui_constraint<X:mode>_and_to_or" |
| 878 |
[(set (match_operand:X 0 "register_operand" "=r") |
| 879 |
(plus:X (and:X (match_operand:X 1 "register_operand" "r") |
| 880 |
(match_operand 2 "const_int_operand")) |
| 881 |
(match_operand 3 "const_int_operand"))) |
| 882 |
(clobber (match_scratch:X 4 "=&r"))] |
| 883 |
"(LUI_OPERAND (~INTVAL (operands[2])) |
| 884 |
&& ((INTVAL (operands[2]) & (-INTVAL (operands[3]))) |
| 885 |
== (-INTVAL (operands[3]))) |
| 886 |
&& riscv_const_insns (operands[3], false) |
| 887 |
&& (riscv_const_insns (GEN_INT (~INTVAL (operands[2]) |
| 888 |
| -INTVAL (operands[3])), false) |
| 889 |
<= riscv_const_insns (operands[3], false)))" |
| 890 |
"#" |
| 891 |
"&& reload_completed" |
| 892 |
[(const_int 0)] |
| 893 |
{ |
| 894 |
operands[5] = GEN_INT (~INTVAL (operands[2])); |
| 895 |
operands[6] = GEN_INT ((~INTVAL (operands[2])) | (-INTVAL (operands[3]))); |
| 896 |
|
| 897 |
/* This is always a LUI operand, so it's safe to just emit. */ |
| 898 |
emit_move_insn (operands[4], operands[5]); |
| 899 |
|
| 900 |
rtx x = gen_rtx_IOR (word_mode, operands[1], operands[4]); |
| 901 |
emit_move_insn (operands[0], x); |
| 902 |
|
| 903 |
/* This may require multiple steps to synthesize. */ |
| 904 |
riscv_emit_move (operands[4], operands[6]); |
| 905 |
x = gen_rtx_MINUS (word_mode, operands[0], operands[4]); |
| 906 |
emit_move_insn (operands[0], x); |
| 907 |
} |
| 908 |
[(set_attr "type" "arith")]) |
| 909 |
|
| 910 |
;; |
| 911 |
;; .................... |
| 912 |
;; |
| 913 |
;; SUBTRACTION |
| 914 |
;; |
| 915 |
;; .................... |
| 916 |
;; |
| 917 |
|
| 918 |
(define_insn "sub<mode>3" |
| 919 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 920 |
(minus:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 921 |
(match_operand:ANYF 2 "register_operand" " f")))] |
| 922 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 923 |
"fsub.<fmt>\t%0,%1,%2" |
| 924 |
[(set_attr "type" "fadd") |
| 925 |
(set_attr "mode" "<UNITMODE>")]) |
| 926 |
|
| 927 |
(define_insn "subdi3" |
| 928 |
[(set (match_operand:DI 0 "register_operand" "= r") |
| 929 |
(minus:DI (match_operand:DI 1 "reg_or_0_operand" " rJ") |
| 930 |
(match_operand:DI 2 "register_operand" " r")))] |
| 931 |
"TARGET_64BIT" |
| 932 |
"sub\t%0,%z1,%2" |
| 933 |
[(set_attr "type" "arith") |
| 934 |
(set_attr "mode" "DI")]) |
| 935 |
|
| 936 |
(define_insn "*subsi3" |
| 937 |
[(set (match_operand:SI 0 "register_operand" "= r") |
| 938 |
(minus:SI (match_operand:SI 1 "reg_or_0_operand" " rJ") |
| 939 |
(match_operand:SI 2 "register_operand" " r")))] |
| 940 |
"" |
| 941 |
"sub%~\t%0,%z1,%2" |
| 942 |
[(set_attr "type" "arith") |
| 943 |
(set_attr "mode" "SI")]) |
| 944 |
|
| 945 |
(define_expand "subsi3" |
| 946 |
[(set (match_operand:SI 0 "register_operand" "= r") |
| 947 |
(minus:SI (match_operand:SI 1 "reg_or_0_operand" " rJ") |
| 948 |
(match_operand:SI 2 "register_operand" " r")))] |
| 949 |
"" |
| 950 |
{ |
| 951 |
if (TARGET_64BIT) |
| 952 |
{ |
| 953 |
rtx t = gen_reg_rtx (DImode); |
| 954 |
emit_insn (gen_subsi3_extended (t, operands[1], operands[2])); |
| 955 |
t = gen_lowpart (SImode, t); |
| 956 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 957 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 958 |
emit_move_insn (operands[0], t); |
| 959 |
DONE; |
| 960 |
} |
| 961 |
}) |
| 962 |
|
| 963 |
(define_expand "subv<mode>4" |
| 964 |
[(set (match_operand:GPR 0 "register_operand" "= r") |
| 965 |
(minus:GPR (match_operand:GPR 1 "reg_or_0_operand" " rJ") |
| 966 |
(match_operand:GPR 2 "register_operand" " r"))) |
| 967 |
(label_ref (match_operand 3 "" ""))] |
| 968 |
"" |
| 969 |
{ |
| 970 |
if (TARGET_64BIT && <MODE>mode == SImode) |
| 971 |
{ |
| 972 |
rtx t3 = gen_reg_rtx (DImode); |
| 973 |
rtx t4 = gen_reg_rtx (DImode); |
| 974 |
rtx t5 = gen_reg_rtx (DImode); |
| 975 |
rtx t6 = gen_reg_rtx (DImode); |
| 976 |
|
| 977 |
riscv_emit_binary (MINUS, operands[0], operands[1], operands[2]); |
| 978 |
if (GET_CODE (operands[1]) != CONST_INT) |
| 979 |
emit_insn (gen_extend_insn (t4, operands[1], DImode, SImode, 0)); |
| 980 |
else |
| 981 |
t4 = operands[1]; |
| 982 |
if (GET_CODE (operands[2]) != CONST_INT) |
| 983 |
emit_insn (gen_extend_insn (t5, operands[2], DImode, SImode, 0)); |
| 984 |
else |
| 985 |
t5 = operands[2]; |
| 986 |
emit_insn (gen_subdi3 (t3, t4, t5)); |
| 987 |
emit_insn (gen_extend_insn (t6, operands[0], DImode, SImode, 0)); |
| 988 |
|
| 989 |
riscv_expand_conditional_branch (operands[3], NE, t6, t3); |
| 990 |
} |
| 991 |
else |
| 992 |
{ |
| 993 |
rtx t3 = gen_reg_rtx (<MODE>mode); |
| 994 |
rtx t4 = gen_reg_rtx (<MODE>mode); |
| 995 |
|
| 996 |
emit_insn (gen_sub3_insn (operands[0], operands[1], operands[2])); |
| 997 |
|
| 998 |
rtx cmp1 = gen_rtx_LT (<MODE>mode, operands[2], const0_rtx); |
| 999 |
emit_insn (gen_cstore<mode>4 (t3, cmp1, operands[2], const0_rtx)); |
| 1000 |
|
| 1001 |
rtx cmp2 = gen_rtx_LT (<MODE>mode, operands[1], operands[0]); |
| 1002 |
emit_insn (gen_cstore<mode>4 (t4, cmp2, operands[1], operands[0])); |
| 1003 |
|
| 1004 |
riscv_expand_conditional_branch (operands[3], NE, t3, t4); |
| 1005 |
} |
| 1006 |
|
| 1007 |
DONE; |
| 1008 |
}) |
| 1009 |
|
| 1010 |
(define_expand "usubv<mode>4" |
| 1011 |
[(set (match_operand:GPR 0 "register_operand" "= r") |
| 1012 |
(minus:GPR (match_operand:GPR 1 "reg_or_0_operand" " rJ") |
| 1013 |
(match_operand:GPR 2 "register_operand" " r"))) |
| 1014 |
(label_ref (match_operand 3 "" ""))] |
| 1015 |
"" |
| 1016 |
{ |
| 1017 |
if (TARGET_64BIT && <MODE>mode == SImode) |
| 1018 |
{ |
| 1019 |
rtx t3 = gen_reg_rtx (DImode); |
| 1020 |
rtx t4 = gen_reg_rtx (DImode); |
| 1021 |
|
| 1022 |
if (GET_CODE (operands[1]) != CONST_INT) |
| 1023 |
emit_insn (gen_extend_insn (t3, operands[1], DImode, SImode, 0)); |
| 1024 |
else |
| 1025 |
t3 = operands[1]; |
| 1026 |
riscv_emit_binary (MINUS, operands[0], operands[1], operands[2]); |
| 1027 |
emit_insn (gen_extend_insn (t4, operands[0], DImode, SImode, 0)); |
| 1028 |
|
| 1029 |
riscv_expand_conditional_branch (operands[3], LTU, t3, t4); |
| 1030 |
} |
| 1031 |
else |
| 1032 |
{ |
| 1033 |
emit_insn (gen_sub3_insn (operands[0], operands[1], operands[2])); |
| 1034 |
riscv_expand_conditional_branch (operands[3], LTU, operands[1], |
| 1035 |
operands[0]); |
| 1036 |
} |
| 1037 |
|
| 1038 |
DONE; |
| 1039 |
}) |
| 1040 |
|
| 1041 |
|
| 1042 |
(define_insn "subsi3_extended" |
| 1043 |
[(set (match_operand:DI 0 "register_operand" "= r") |
| 1044 |
(sign_extend:DI |
| 1045 |
(minus:SI (match_operand:SI 1 "reg_or_0_operand" " rJ") |
| 1046 |
(match_operand:SI 2 "register_operand" " r"))))] |
| 1047 |
"TARGET_64BIT" |
| 1048 |
"subw\t%0,%z1,%2" |
| 1049 |
[(set_attr "type" "arith") |
| 1050 |
(set_attr "mode" "SI")]) |
| 1051 |
|
| 1052 |
(define_insn "*subsi3_extended2" |
| 1053 |
[(set (match_operand:DI 0 "register_operand" "= r") |
| 1054 |
(sign_extend:DI |
| 1055 |
(match_operator:SI 3 "subreg_lowpart_operator" |
| 1056 |
[(minus:DI (match_operand:DI 1 "reg_or_0_operand" " rJ") |
| 1057 |
(match_operand:DI 2 "register_operand" " r"))])))] |
| 1058 |
"TARGET_64BIT" |
| 1059 |
"subw\t%0,%z1,%2" |
| 1060 |
[(set_attr "type" "arith") |
| 1061 |
(set_attr "mode" "SI")]) |
| 1062 |
|
| 1063 |
(define_insn "negdi2" |
| 1064 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1065 |
(neg:DI (match_operand:DI 1 "register_operand" " r")))] |
| 1066 |
"TARGET_64BIT" |
| 1067 |
"neg\t%0,%1" |
| 1068 |
[(set_attr "type" "arith") |
| 1069 |
(set_attr "mode" "DI")]) |
| 1070 |
|
| 1071 |
(define_insn "*negsi2" |
| 1072 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1073 |
(neg:SI (match_operand:SI 1 "register_operand" " r")))] |
| 1074 |
"" |
| 1075 |
"neg%~\t%0,%1" |
| 1076 |
[(set_attr "type" "arith") |
| 1077 |
(set_attr "mode" "SI")]) |
| 1078 |
|
| 1079 |
(define_expand "negsi2" |
| 1080 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1081 |
(neg:SI (match_operand:SI 1 "register_operand" " r")))] |
| 1082 |
"" |
| 1083 |
{ |
| 1084 |
if (TARGET_64BIT) |
| 1085 |
{ |
| 1086 |
rtx t = gen_reg_rtx (DImode); |
| 1087 |
emit_insn (gen_negsi2_extended (t, operands[1])); |
| 1088 |
t = gen_lowpart (SImode, t); |
| 1089 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 1090 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 1091 |
emit_move_insn (operands[0], t); |
| 1092 |
DONE; |
| 1093 |
} |
| 1094 |
}) |
| 1095 |
|
| 1096 |
(define_insn "negsi2_extended" |
| 1097 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1098 |
(sign_extend:DI |
| 1099 |
(neg:SI (match_operand:SI 1 "register_operand" " r"))))] |
| 1100 |
"TARGET_64BIT" |
| 1101 |
"negw\t%0,%1" |
| 1102 |
[(set_attr "type" "arith") |
| 1103 |
(set_attr "mode" "SI")]) |
| 1104 |
|
| 1105 |
(define_insn "*negsi2_extended2" |
| 1106 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1107 |
(sign_extend:DI |
| 1108 |
(match_operator:SI 2 "subreg_lowpart_operator" |
| 1109 |
[(neg:DI (match_operand:DI 1 "register_operand" " r"))])))] |
| 1110 |
"TARGET_64BIT" |
| 1111 |
"negw\t%0,%1" |
| 1112 |
[(set_attr "type" "arith") |
| 1113 |
(set_attr "mode" "SI")]) |
| 1114 |
|
| 1115 |
;; |
| 1116 |
;; .................... |
| 1117 |
;; |
| 1118 |
;; MULTIPLICATION |
| 1119 |
;; |
| 1120 |
;; .................... |
| 1121 |
;; |
| 1122 |
|
| 1123 |
(define_insn "mul<mode>3" |
| 1124 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1125 |
(mult:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 1126 |
(match_operand:ANYF 2 "register_operand" " f")))] |
| 1127 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1128 |
"fmul.<fmt>\t%0,%1,%2" |
| 1129 |
[(set_attr "type" "fmul") |
| 1130 |
(set_attr "mode" "<UNITMODE>")]) |
| 1131 |
|
| 1132 |
(define_insn "*mulsi3" |
| 1133 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1134 |
(mult:SI (match_operand:SI 1 "register_operand" " r") |
| 1135 |
(match_operand:SI 2 "register_operand" " r")))] |
| 1136 |
"TARGET_ZMMUL || TARGET_MUL" |
| 1137 |
"mul%~\t%0,%1,%2" |
| 1138 |
[(set_attr "type" "imul") |
| 1139 |
(set_attr "mode" "SI")]) |
| 1140 |
|
| 1141 |
(define_expand "mulsi3" |
| 1142 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1143 |
(mult:SI (match_operand:SI 1 "register_operand" " r") |
| 1144 |
(match_operand:SI 2 "register_operand" " r")))] |
| 1145 |
"TARGET_ZMMUL || TARGET_MUL" |
| 1146 |
{ |
| 1147 |
if (TARGET_64BIT) |
| 1148 |
{ |
| 1149 |
rtx t = gen_reg_rtx (DImode); |
| 1150 |
emit_insn (gen_mulsi3_extended (t, operands[1], operands[2])); |
| 1151 |
t = gen_lowpart (SImode, t); |
| 1152 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 1153 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 1154 |
emit_move_insn (operands[0], t); |
| 1155 |
DONE; |
| 1156 |
} |
| 1157 |
}) |
| 1158 |
|
| 1159 |
(define_insn "muldi3" |
| 1160 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1161 |
(mult:DI (match_operand:DI 1 "register_operand" " r") |
| 1162 |
(match_operand:DI 2 "register_operand" " r")))] |
| 1163 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1164 |
"mul\t%0,%1,%2" |
| 1165 |
[(set_attr "type" "imul") |
| 1166 |
(set_attr "mode" "DI")]) |
| 1167 |
|
| 1168 |
(define_expand "mulv<mode>4" |
| 1169 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 1170 |
(mult:GPR (match_operand:GPR 1 "register_operand" " r") |
| 1171 |
(match_operand:GPR 2 "register_operand" " r"))) |
| 1172 |
(label_ref (match_operand 3 "" ""))] |
| 1173 |
"TARGET_ZMMUL || TARGET_MUL" |
| 1174 |
{ |
| 1175 |
if (TARGET_64BIT && <MODE>mode == SImode) |
| 1176 |
{ |
| 1177 |
rtx t3 = gen_reg_rtx (DImode); |
| 1178 |
rtx t4 = gen_reg_rtx (DImode); |
| 1179 |
rtx t5 = gen_reg_rtx (DImode); |
| 1180 |
rtx t6 = gen_reg_rtx (DImode); |
| 1181 |
|
| 1182 |
if (GET_CODE (operands[1]) != CONST_INT) |
| 1183 |
emit_insn (gen_extend_insn (t4, operands[1], DImode, SImode, 0)); |
| 1184 |
else |
| 1185 |
t4 = operands[1]; |
| 1186 |
if (GET_CODE (operands[2]) != CONST_INT) |
| 1187 |
emit_insn (gen_extend_insn (t5, operands[2], DImode, SImode, 0)); |
| 1188 |
else |
| 1189 |
t5 = operands[2]; |
| 1190 |
emit_insn (gen_muldi3 (t3, t4, t5)); |
| 1191 |
|
| 1192 |
emit_move_insn (operands[0], gen_lowpart (SImode, t3)); |
| 1193 |
emit_insn (gen_extend_insn (t6, operands[0], DImode, SImode, 0)); |
| 1194 |
|
| 1195 |
riscv_expand_conditional_branch (operands[3], NE, t6, t3); |
| 1196 |
} |
| 1197 |
else |
| 1198 |
{ |
| 1199 |
rtx hp = gen_reg_rtx (<MODE>mode); |
| 1200 |
rtx lp = gen_reg_rtx (<MODE>mode); |
| 1201 |
|
| 1202 |
emit_insn (gen_smul<mode>3_highpart (hp, operands[1], operands[2])); |
| 1203 |
emit_insn (gen_mul<mode>3 (operands[0], operands[1], operands[2])); |
| 1204 |
riscv_emit_binary (ASHIFTRT, lp, operands[0], |
| 1205 |
GEN_INT (BITS_PER_WORD - 1)); |
| 1206 |
|
| 1207 |
riscv_expand_conditional_branch (operands[3], NE, hp, lp); |
| 1208 |
} |
| 1209 |
|
| 1210 |
DONE; |
| 1211 |
}) |
| 1212 |
|
| 1213 |
(define_expand "umulv<mode>4" |
| 1214 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 1215 |
(mult:GPR (match_operand:GPR 1 "register_operand" " r") |
| 1216 |
(match_operand:GPR 2 "register_operand" " r"))) |
| 1217 |
(label_ref (match_operand 3 "" ""))] |
| 1218 |
"TARGET_ZMMUL || TARGET_MUL" |
| 1219 |
{ |
| 1220 |
if (TARGET_64BIT && <MODE>mode == SImode) |
| 1221 |
{ |
| 1222 |
rtx t3 = gen_reg_rtx (DImode); |
| 1223 |
rtx t4 = gen_reg_rtx (DImode); |
| 1224 |
rtx t5 = gen_reg_rtx (DImode); |
| 1225 |
rtx t6 = gen_reg_rtx (DImode); |
| 1226 |
rtx t7 = gen_reg_rtx (DImode); |
| 1227 |
rtx t8 = gen_reg_rtx (DImode); |
| 1228 |
|
| 1229 |
if (GET_CODE (operands[1]) != CONST_INT) |
| 1230 |
emit_insn (gen_extend_insn (t3, operands[1], DImode, SImode, 0)); |
| 1231 |
else |
| 1232 |
t3 = operands[1]; |
| 1233 |
if (GET_CODE (operands[2]) != CONST_INT) |
| 1234 |
emit_insn (gen_extend_insn (t4, operands[2], DImode, SImode, 0)); |
| 1235 |
else |
| 1236 |
t4 = operands[2]; |
| 1237 |
|
| 1238 |
emit_insn (gen_ashldi3 (t5, t3, GEN_INT (32))); |
| 1239 |
emit_insn (gen_ashldi3 (t6, t4, GEN_INT (32))); |
| 1240 |
emit_insn (gen_umuldi3_highpart (t7, t5, t6)); |
| 1241 |
emit_move_insn (operands[0], gen_lowpart (SImode, t7)); |
| 1242 |
emit_insn (gen_lshrdi3 (t8, t7, GEN_INT (32))); |
| 1243 |
|
| 1244 |
riscv_expand_conditional_branch (operands[3], NE, t8, const0_rtx); |
| 1245 |
} |
| 1246 |
else |
| 1247 |
{ |
| 1248 |
rtx hp = gen_reg_rtx (<MODE>mode); |
| 1249 |
|
| 1250 |
emit_insn (gen_umul<mode>3_highpart (hp, operands[1], operands[2])); |
| 1251 |
emit_insn (gen_mul<mode>3 (operands[0], operands[1], operands[2])); |
| 1252 |
|
| 1253 |
riscv_expand_conditional_branch (operands[3], NE, hp, const0_rtx); |
| 1254 |
} |
| 1255 |
|
| 1256 |
DONE; |
| 1257 |
}) |
| 1258 |
|
| 1259 |
(define_insn "mulsi3_extended" |
| 1260 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1261 |
(sign_extend:DI |
| 1262 |
(mult:SI (match_operand:SI 1 "register_operand" " r") |
| 1263 |
(match_operand:SI 2 "register_operand" " r"))))] |
| 1264 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1265 |
"mulw\t%0,%1,%2" |
| 1266 |
[(set_attr "type" "imul") |
| 1267 |
(set_attr "mode" "SI")]) |
| 1268 |
|
| 1269 |
(define_insn "*mulsi3_extended2" |
| 1270 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1271 |
(sign_extend:DI |
| 1272 |
(match_operator:SI 3 "subreg_lowpart_operator" |
| 1273 |
[(mult:DI (match_operand:DI 1 "register_operand" " r") |
| 1274 |
(match_operand:DI 2 "register_operand" " r"))])))] |
| 1275 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1276 |
"mulw\t%0,%1,%2" |
| 1277 |
[(set_attr "type" "imul") |
| 1278 |
(set_attr "mode" "SI")]) |
| 1279 |
|
| 1280 |
;; |
| 1281 |
;; ........................ |
| 1282 |
;; |
| 1283 |
;; MULTIPLICATION HIGH-PART |
| 1284 |
;; |
| 1285 |
;; ........................ |
| 1286 |
;; |
| 1287 |
|
| 1288 |
|
| 1289 |
(define_expand "<u>mulditi3" |
| 1290 |
[(set (match_operand:TI 0 "register_operand") |
| 1291 |
(mult:TI (any_extend:TI (match_operand:DI 1 "register_operand")) |
| 1292 |
(any_extend:TI (match_operand:DI 2 "register_operand"))))] |
| 1293 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1294 |
{ |
| 1295 |
rtx low = gen_reg_rtx (DImode); |
| 1296 |
emit_insn (gen_muldi3 (low, operands[1], operands[2])); |
| 1297 |
|
| 1298 |
rtx high = gen_reg_rtx (DImode); |
| 1299 |
emit_insn (gen_<su>muldi3_highpart (high, operands[1], operands[2])); |
| 1300 |
|
| 1301 |
emit_move_insn (gen_lowpart (DImode, operands[0]), low); |
| 1302 |
emit_move_insn (gen_highpart (DImode, operands[0]), high); |
| 1303 |
DONE; |
| 1304 |
}) |
| 1305 |
|
| 1306 |
(define_insn "<su>muldi3_highpart" |
| 1307 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1308 |
(truncate:DI |
| 1309 |
(lshiftrt:TI |
| 1310 |
(mult:TI (any_extend:TI |
| 1311 |
(match_operand:DI 1 "register_operand" " r")) |
| 1312 |
(any_extend:TI |
| 1313 |
(match_operand:DI 2 "register_operand" " r"))) |
| 1314 |
(const_int 64))))] |
| 1315 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1316 |
"mulh<u>\t%0,%1,%2" |
| 1317 |
[(set_attr "type" "imul") |
| 1318 |
(set_attr "mode" "DI")]) |
| 1319 |
|
| 1320 |
(define_expand "usmulditi3" |
| 1321 |
[(set (match_operand:TI 0 "register_operand") |
| 1322 |
(mult:TI (zero_extend:TI (match_operand:DI 1 "register_operand")) |
| 1323 |
(sign_extend:TI (match_operand:DI 2 "register_operand"))))] |
| 1324 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1325 |
{ |
| 1326 |
rtx low = gen_reg_rtx (DImode); |
| 1327 |
emit_insn (gen_muldi3 (low, operands[1], operands[2])); |
| 1328 |
|
| 1329 |
rtx high = gen_reg_rtx (DImode); |
| 1330 |
emit_insn (gen_usmuldi3_highpart (high, operands[1], operands[2])); |
| 1331 |
|
| 1332 |
emit_move_insn (gen_lowpart (DImode, operands[0]), low); |
| 1333 |
emit_move_insn (gen_highpart (DImode, operands[0]), high); |
| 1334 |
DONE; |
| 1335 |
}) |
| 1336 |
|
| 1337 |
(define_insn "usmuldi3_highpart" |
| 1338 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1339 |
(truncate:DI |
| 1340 |
(lshiftrt:TI |
| 1341 |
(mult:TI (zero_extend:TI |
| 1342 |
(match_operand:DI 1 "register_operand" "r")) |
| 1343 |
(sign_extend:TI |
| 1344 |
(match_operand:DI 2 "register_operand" " r"))) |
| 1345 |
(const_int 64))))] |
| 1346 |
"(TARGET_ZMMUL || TARGET_MUL) && TARGET_64BIT" |
| 1347 |
"mulhsu\t%0,%2,%1" |
| 1348 |
[(set_attr "type" "imul") |
| 1349 |
(set_attr "mode" "DI")]) |
| 1350 |
|
| 1351 |
(define_expand "<u>mulsidi3" |
| 1352 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1353 |
(mult:DI (any_extend:DI |
| 1354 |
(match_operand:SI 1 "register_operand" " r")) |
| 1355 |
(any_extend:DI |
| 1356 |
(match_operand:SI 2 "register_operand" " r"))))] |
| 1357 |
"(TARGET_ZMMUL || TARGET_MUL) && !TARGET_64BIT" |
| 1358 |
{ |
| 1359 |
rtx temp = gen_reg_rtx (SImode); |
| 1360 |
riscv_emit_binary (MULT, temp, operands[1], operands[2]); |
| 1361 |
emit_insn (gen_<su>mulsi3_highpart (riscv_subword (operands[0], true), |
| 1362 |
operands[1], operands[2])); |
| 1363 |
emit_insn (gen_movsi (riscv_subword (operands[0], false), temp)); |
| 1364 |
DONE; |
| 1365 |
}) |
| 1366 |
|
| 1367 |
(define_insn "<su>mulsi3_highpart" |
| 1368 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1369 |
(truncate:SI |
| 1370 |
(lshiftrt:DI |
| 1371 |
(mult:DI (any_extend:DI |
| 1372 |
(match_operand:SI 1 "register_operand" " r")) |
| 1373 |
(any_extend:DI |
| 1374 |
(match_operand:SI 2 "register_operand" " r"))) |
| 1375 |
(const_int 32))))] |
| 1376 |
"(TARGET_ZMMUL || TARGET_MUL) && !TARGET_64BIT" |
| 1377 |
"mulh<u>\t%0,%1,%2" |
| 1378 |
[(set_attr "type" "imul") |
| 1379 |
(set_attr "mode" "SI")]) |
| 1380 |
|
| 1381 |
|
| 1382 |
(define_expand "usmulsidi3" |
| 1383 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1384 |
(mult:DI (zero_extend:DI |
| 1385 |
(match_operand:SI 1 "register_operand" " r")) |
| 1386 |
(sign_extend:DI |
| 1387 |
(match_operand:SI 2 "register_operand" " r"))))] |
| 1388 |
"(TARGET_ZMMUL || TARGET_MUL) && !TARGET_64BIT" |
| 1389 |
{ |
| 1390 |
rtx temp = gen_reg_rtx (SImode); |
| 1391 |
riscv_emit_binary (MULT, temp, operands[1], operands[2]); |
| 1392 |
emit_insn (gen_usmulsi3_highpart (riscv_subword (operands[0], true), |
| 1393 |
operands[1], operands[2])); |
| 1394 |
emit_insn (gen_movsi (riscv_subword (operands[0], false), temp)); |
| 1395 |
DONE; |
| 1396 |
}) |
| 1397 |
|
| 1398 |
(define_insn "usmulsi3_highpart" |
| 1399 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1400 |
(truncate:SI |
| 1401 |
(lshiftrt:DI |
| 1402 |
(mult:DI (zero_extend:DI |
| 1403 |
(match_operand:SI 1 "register_operand" " r")) |
| 1404 |
(sign_extend:DI |
| 1405 |
(match_operand:SI 2 "register_operand" " r"))) |
| 1406 |
(const_int 32))))] |
| 1407 |
"(TARGET_ZMMUL || TARGET_MUL) && !TARGET_64BIT" |
| 1408 |
"mulhsu\t%0,%2,%1" |
| 1409 |
[(set_attr "type" "imul") |
| 1410 |
(set_attr "mode" "SI")]) |
| 1411 |
|
| 1412 |
;; |
| 1413 |
;; .................... |
| 1414 |
;; |
| 1415 |
;; DIVISION and REMAINDER |
| 1416 |
;; |
| 1417 |
;; .................... |
| 1418 |
;; |
| 1419 |
|
| 1420 |
(define_insn "*<optab>si3" |
| 1421 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1422 |
(any_div:SI (match_operand:SI 1 "register_operand" " r") |
| 1423 |
(match_operand:SI 2 "register_operand" " r")))] |
| 1424 |
"TARGET_DIV" |
| 1425 |
"<insn>%i2%~\t%0,%1,%2" |
| 1426 |
[(set_attr "type" "idiv") |
| 1427 |
(set_attr "mode" "SI")]) |
| 1428 |
|
| 1429 |
(define_expand "<optab>si3" |
| 1430 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1431 |
(any_div:SI (match_operand:SI 1 "register_operand" " r") |
| 1432 |
(match_operand:SI 2 "register_operand" " r")))] |
| 1433 |
"TARGET_DIV" |
| 1434 |
{ |
| 1435 |
if (TARGET_64BIT) |
| 1436 |
{ |
| 1437 |
rtx t = gen_reg_rtx (DImode); |
| 1438 |
emit_insn (gen_<optab>si3_extended (t, operands[1], operands[2])); |
| 1439 |
t = gen_lowpart (SImode, t); |
| 1440 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 1441 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 1442 |
emit_move_insn (operands[0], t); |
| 1443 |
DONE; |
| 1444 |
} |
| 1445 |
}) |
| 1446 |
|
| 1447 |
(define_insn "<optab>di3" |
| 1448 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1449 |
(any_div:DI (match_operand:DI 1 "register_operand" " r") |
| 1450 |
(match_operand:DI 2 "register_operand" " r")))] |
| 1451 |
"TARGET_DIV && TARGET_64BIT" |
| 1452 |
"<insn>%i2\t%0,%1,%2" |
| 1453 |
[(set_attr "type" "idiv") |
| 1454 |
(set_attr "mode" "DI")]) |
| 1455 |
|
| 1456 |
(define_expand "<u>divmod<mode>4" |
| 1457 |
[(parallel |
| 1458 |
[(set (match_operand:GPR 0 "register_operand") |
| 1459 |
(only_div:GPR (match_operand:GPR 1 "register_operand") |
| 1460 |
(match_operand:GPR 2 "register_operand"))) |
| 1461 |
(set (match_operand:GPR 3 "register_operand") |
| 1462 |
(<paired_mod>:GPR (match_dup 1) (match_dup 2)))])] |
| 1463 |
"TARGET_DIV && riscv_use_divmod_expander ()" |
| 1464 |
{ |
| 1465 |
rtx tmp = gen_reg_rtx (<MODE>mode); |
| 1466 |
emit_insn (gen_<u>div<GPR:mode>3 (operands[0], operands[1], operands[2])); |
| 1467 |
emit_insn (gen_mul<GPR:mode>3 (tmp, operands[0], operands[2])); |
| 1468 |
emit_insn (gen_sub<GPR:mode>3 (operands[3], operands[1], tmp)); |
| 1469 |
DONE; |
| 1470 |
}) |
| 1471 |
|
| 1472 |
(define_insn "<optab>si3_extended" |
| 1473 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1474 |
(sign_extend:DI |
| 1475 |
(any_div:SI (match_operand:SI 1 "register_operand" " r") |
| 1476 |
(match_operand:SI 2 "register_operand" " r"))))] |
| 1477 |
"TARGET_DIV && TARGET_64BIT" |
| 1478 |
"<insn>%i2w\t%0,%1,%2" |
| 1479 |
[(set_attr "type" "idiv") |
| 1480 |
(set_attr "mode" "DI")]) |
| 1481 |
|
| 1482 |
(define_insn "div<mode>3" |
| 1483 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1484 |
(div:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 1485 |
(match_operand:ANYF 2 "register_operand" " f")))] |
| 1486 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && TARGET_FDIV" |
| 1487 |
"fdiv.<fmt>\t%0,%1,%2" |
| 1488 |
[(set_attr "type" "fdiv") |
| 1489 |
(set_attr "mode" "<UNITMODE>")]) |
| 1490 |
|
| 1491 |
;; |
| 1492 |
;; .................... |
| 1493 |
;; |
| 1494 |
;; SQUARE ROOT |
| 1495 |
;; |
| 1496 |
;; .................... |
| 1497 |
|
| 1498 |
(define_insn "sqrt<mode>2" |
| 1499 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1500 |
(sqrt:ANYF (match_operand:ANYF 1 "register_operand" " f")))] |
| 1501 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && TARGET_FDIV" |
| 1502 |
{ |
| 1503 |
return "fsqrt.<fmt>\t%0,%1"; |
| 1504 |
} |
| 1505 |
[(set_attr "type" "fsqrt") |
| 1506 |
(set_attr "mode" "<UNITMODE>")]) |
| 1507 |
|
| 1508 |
;; Floating point multiply accumulate instructions. |
| 1509 |
|
| 1510 |
;; a * b + c |
| 1511 |
(define_insn "fma<mode>4" |
| 1512 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1513 |
(fma:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 1514 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1515 |
(match_operand:ANYF 3 "register_operand" " f")))] |
| 1516 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1517 |
"fmadd.<fmt>\t%0,%1,%2,%3" |
| 1518 |
[(set_attr "type" "fmadd") |
| 1519 |
(set_attr "mode" "<UNITMODE>")]) |
| 1520 |
|
| 1521 |
;; a * b - c |
| 1522 |
(define_insn "fms<mode>4" |
| 1523 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1524 |
(fma:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 1525 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1526 |
(neg:ANYF (match_operand:ANYF 3 "register_operand" " f"))))] |
| 1527 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1528 |
"fmsub.<fmt>\t%0,%1,%2,%3" |
| 1529 |
[(set_attr "type" "fmadd") |
| 1530 |
(set_attr "mode" "<UNITMODE>")]) |
| 1531 |
|
| 1532 |
;; -a * b - c |
| 1533 |
(define_insn "fnms<mode>4" |
| 1534 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1535 |
(fma:ANYF |
| 1536 |
(neg:ANYF (match_operand:ANYF 1 "register_operand" " f")) |
| 1537 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1538 |
(neg:ANYF (match_operand:ANYF 3 "register_operand" " f"))))] |
| 1539 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1540 |
"fnmadd.<fmt>\t%0,%1,%2,%3" |
| 1541 |
[(set_attr "type" "fmadd") |
| 1542 |
(set_attr "mode" "<UNITMODE>")]) |
| 1543 |
|
| 1544 |
;; -a * b + c |
| 1545 |
(define_insn "fnma<mode>4" |
| 1546 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1547 |
(fma:ANYF |
| 1548 |
(neg:ANYF (match_operand:ANYF 1 "register_operand" " f")) |
| 1549 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1550 |
(match_operand:ANYF 3 "register_operand" " f")))] |
| 1551 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1552 |
"fnmsub.<fmt>\t%0,%1,%2,%3" |
| 1553 |
[(set_attr "type" "fmadd") |
| 1554 |
(set_attr "mode" "<UNITMODE>")]) |
| 1555 |
|
| 1556 |
;; -(-a * b - c), modulo signed zeros |
| 1557 |
(define_insn "*fma<mode>4" |
| 1558 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1559 |
(neg:ANYF |
| 1560 |
(fma:ANYF |
| 1561 |
(neg:ANYF (match_operand:ANYF 1 "register_operand" " f")) |
| 1562 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1563 |
(neg:ANYF (match_operand:ANYF 3 "register_operand" " f")))))] |
| 1564 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && !HONOR_SIGNED_ZEROS (<MODE>mode)" |
| 1565 |
"fmadd.<fmt>\t%0,%1,%2,%3" |
| 1566 |
[(set_attr "type" "fmadd") |
| 1567 |
(set_attr "mode" "<UNITMODE>")]) |
| 1568 |
|
| 1569 |
;; -(-a * b + c), modulo signed zeros |
| 1570 |
(define_insn "*fms<mode>4" |
| 1571 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1572 |
(neg:ANYF |
| 1573 |
(fma:ANYF |
| 1574 |
(neg:ANYF (match_operand:ANYF 1 "register_operand" " f")) |
| 1575 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1576 |
(match_operand:ANYF 3 "register_operand" " f"))))] |
| 1577 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && !HONOR_SIGNED_ZEROS (<MODE>mode)" |
| 1578 |
"fmsub.<fmt>\t%0,%1,%2,%3" |
| 1579 |
[(set_attr "type" "fmadd") |
| 1580 |
(set_attr "mode" "<UNITMODE>")]) |
| 1581 |
|
| 1582 |
;; -(a * b + c), modulo signed zeros |
| 1583 |
(define_insn "*fnms<mode>4" |
| 1584 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1585 |
(neg:ANYF |
| 1586 |
(fma:ANYF |
| 1587 |
(match_operand:ANYF 1 "register_operand" " f") |
| 1588 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1589 |
(match_operand:ANYF 3 "register_operand" " f"))))] |
| 1590 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && !HONOR_SIGNED_ZEROS (<MODE>mode)" |
| 1591 |
"fnmadd.<fmt>\t%0,%1,%2,%3" |
| 1592 |
[(set_attr "type" "fmadd") |
| 1593 |
(set_attr "mode" "<UNITMODE>")]) |
| 1594 |
|
| 1595 |
;; -(a * b - c), modulo signed zeros |
| 1596 |
(define_insn "*fnma<mode>4" |
| 1597 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1598 |
(neg:ANYF |
| 1599 |
(fma:ANYF |
| 1600 |
(match_operand:ANYF 1 "register_operand" " f") |
| 1601 |
(match_operand:ANYF 2 "register_operand" " f") |
| 1602 |
(neg:ANYF (match_operand:ANYF 3 "register_operand" " f")))))] |
| 1603 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && !HONOR_SIGNED_ZEROS (<MODE>mode)" |
| 1604 |
"fnmsub.<fmt>\t%0,%1,%2,%3" |
| 1605 |
[(set_attr "type" "fmadd") |
| 1606 |
(set_attr "mode" "<UNITMODE>")]) |
| 1607 |
|
| 1608 |
;; |
| 1609 |
;; .................... |
| 1610 |
;; |
| 1611 |
;; SIGN INJECTION |
| 1612 |
;; |
| 1613 |
;; .................... |
| 1614 |
|
| 1615 |
(define_insn "abs<mode>2" |
| 1616 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1617 |
(abs:ANYF (match_operand:ANYF 1 "register_operand" " f")))] |
| 1618 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1619 |
"fabs.<fmt>\t%0,%1" |
| 1620 |
[(set_attr "type" "fmove") |
| 1621 |
(set_attr "mode" "<UNITMODE>")]) |
| 1622 |
|
| 1623 |
(define_insn "copysign<mode>3" |
| 1624 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1625 |
(unspec:ANYF [(match_operand:ANYF 1 "register_operand" " f") |
| 1626 |
(match_operand:ANYF 2 "register_operand" " f")] |
| 1627 |
UNSPEC_COPYSIGN))] |
| 1628 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1629 |
"fsgnj.<fmt>\t%0,%1,%2" |
| 1630 |
[(set_attr "type" "fmove") |
| 1631 |
(set_attr "mode" "<UNITMODE>")]) |
| 1632 |
|
| 1633 |
(define_insn "neg<mode>2" |
| 1634 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1635 |
(neg:ANYF (match_operand:ANYF 1 "register_operand" " f")))] |
| 1636 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1637 |
"fneg.<fmt>\t%0,%1" |
| 1638 |
[(set_attr "type" "fmove") |
| 1639 |
(set_attr "mode" "<UNITMODE>")]) |
| 1640 |
|
| 1641 |
;; |
| 1642 |
;; .................... |
| 1643 |
;; |
| 1644 |
;; MIN/MAX |
| 1645 |
;; |
| 1646 |
;; .................... |
| 1647 |
|
| 1648 |
(define_insn "fminm<mode>3" |
| 1649 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1650 |
(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" " f")) |
| 1651 |
(use (match_operand:ANYF 2 "register_operand" " f"))] |
| 1652 |
UNSPEC_FMINM))] |
| 1653 |
"TARGET_HARD_FLOAT && TARGET_ZFA" |
| 1654 |
"fminm.<fmt>\t%0,%1,%2" |
| 1655 |
[(set_attr "type" "fmove") |
| 1656 |
(set_attr "mode" "<UNITMODE>")]) |
| 1657 |
|
| 1658 |
(define_insn "fmaxm<mode>3" |
| 1659 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1660 |
(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" " f")) |
| 1661 |
(use (match_operand:ANYF 2 "register_operand" " f"))] |
| 1662 |
UNSPEC_FMAXM))] |
| 1663 |
"TARGET_HARD_FLOAT && TARGET_ZFA" |
| 1664 |
"fmaxm.<fmt>\t%0,%1,%2" |
| 1665 |
[(set_attr "type" "fmove") |
| 1666 |
(set_attr "mode" "<UNITMODE>")]) |
| 1667 |
|
| 1668 |
(define_insn "fmin<mode>3" |
| 1669 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1670 |
(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" " f")) |
| 1671 |
(use (match_operand:ANYF 2 "register_operand" " f"))] |
| 1672 |
UNSPEC_FMIN))] |
| 1673 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && !HONOR_SNANS (<MODE>mode)" |
| 1674 |
"fmin.<fmt>\t%0,%1,%2" |
| 1675 |
[(set_attr "type" "fmove") |
| 1676 |
(set_attr "mode" "<UNITMODE>")]) |
| 1677 |
|
| 1678 |
(define_insn "fmax<mode>3" |
| 1679 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1680 |
(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" " f")) |
| 1681 |
(use (match_operand:ANYF 2 "register_operand" " f"))] |
| 1682 |
UNSPEC_FMAX))] |
| 1683 |
"(TARGET_HARD_FLOAT || TARGET_ZFINX) && !HONOR_SNANS (<MODE>mode)" |
| 1684 |
"fmax.<fmt>\t%0,%1,%2" |
| 1685 |
[(set_attr "type" "fmove") |
| 1686 |
(set_attr "mode" "<UNITMODE>")]) |
| 1687 |
|
| 1688 |
(define_insn "smin<mode>3" |
| 1689 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1690 |
(smin:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 1691 |
(match_operand:ANYF 2 "register_operand" " f")))] |
| 1692 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1693 |
"fmin.<fmt>\t%0,%1,%2" |
| 1694 |
[(set_attr "type" "fmove") |
| 1695 |
(set_attr "mode" "<UNITMODE>")]) |
| 1696 |
|
| 1697 |
(define_insn "smax<mode>3" |
| 1698 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 1699 |
(smax:ANYF (match_operand:ANYF 1 "register_operand" " f") |
| 1700 |
(match_operand:ANYF 2 "register_operand" " f")))] |
| 1701 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 1702 |
"fmax.<fmt>\t%0,%1,%2" |
| 1703 |
[(set_attr "type" "fmove") |
| 1704 |
(set_attr "mode" "<UNITMODE>")]) |
| 1705 |
|
| 1706 |
;; |
| 1707 |
;; .................... |
| 1708 |
;; |
| 1709 |
;; LOGICAL |
| 1710 |
;; |
| 1711 |
;; .................... |
| 1712 |
;; |
| 1713 |
|
| 1714 |
;; For RV64, we don't expose the SImode operations to the rtl expanders, |
| 1715 |
;; but SImode versions exist for combine. |
| 1716 |
|
| 1717 |
(define_expand "and<mode>3" |
| 1718 |
[(set (match_operand:X 0 "register_operand") |
| 1719 |
(and:X (match_operand:X 1 "register_operand") |
| 1720 |
(match_operand:X 2 "arith_or_mode_mask_or_zbs_operand")))] |
| 1721 |
"" |
| 1722 |
{ |
| 1723 |
/* If the second operand is a mode mask, emit an extension |
| 1724 |
insn instead. */ |
| 1725 |
if (CONST_INT_P (operands[2])) |
| 1726 |
{ |
| 1727 |
enum machine_mode tmode = VOIDmode; |
| 1728 |
if (UINTVAL (operands[2]) == GET_MODE_MASK (HImode)) |
| 1729 |
tmode = HImode; |
| 1730 |
else if (UINTVAL (operands[2]) == GET_MODE_MASK (SImode)) |
| 1731 |
tmode = SImode; |
| 1732 |
|
| 1733 |
if (tmode != VOIDmode) |
| 1734 |
{ |
| 1735 |
rtx tmp = gen_lowpart (tmode, operands[1]); |
| 1736 |
emit_insn (gen_extend_insn (operands[0], tmp, <MODE>mode, tmode, 1)); |
| 1737 |
DONE; |
| 1738 |
} |
| 1739 |
} |
| 1740 |
}) |
| 1741 |
|
| 1742 |
(define_insn "*and<mode>3" |
| 1743 |
[(set (match_operand:X 0 "register_operand" "=r,r") |
| 1744 |
(and:X (match_operand:X 1 "register_operand" "%r,r") |
| 1745 |
(match_operand:X 2 "arith_operand" " r,I")))] |
| 1746 |
"" |
| 1747 |
"and%i2\t%0,%1,%2" |
| 1748 |
[(set_attr "type" "logical") |
| 1749 |
(set_attr "mode" "<MODE>")]) |
| 1750 |
|
| 1751 |
;; When we construct constants we may want to twiddle a single bit |
| 1752 |
;; by generating an IOR. But the constant likely doesn't fit |
| 1753 |
;; arith_operand. So the generic code will reload the constant into |
| 1754 |
;; a register. Post-reload we won't have the chance to squash things |
| 1755 |
;; back into a Zbs insn. |
| 1756 |
;; |
| 1757 |
;; So indirect through a define_expand. That allows us to have a |
| 1758 |
;; predicate that conditionally accepts single bit constants without |
| 1759 |
;; putting the details of Zbs instructions in here. |
| 1760 |
(define_expand "<optab><mode>3" |
| 1761 |
[(set (match_operand:X 0 "register_operand") |
| 1762 |
(any_or:X (match_operand:X 1 "register_operand" "") |
| 1763 |
(match_operand:X 2 "arith_or_zbs_operand" "")))] |
| 1764 |
"") |
| 1765 |
|
| 1766 |
(define_insn "*<optab><mode>3" |
| 1767 |
[(set (match_operand:X 0 "register_operand" "=r,r") |
| 1768 |
(any_or:X (match_operand:X 1 "register_operand" "%r,r") |
| 1769 |
(match_operand:X 2 "arith_operand" " r,I")))] |
| 1770 |
"" |
| 1771 |
"<insn>%i2\t%0,%1,%2" |
| 1772 |
[(set_attr "type" "logical") |
| 1773 |
(set_attr "mode" "<MODE>")]) |
| 1774 |
|
| 1775 |
(define_insn "*<optab>si3_internal" |
| 1776 |
[(set (match_operand:SI 0 "register_operand" "=r,r") |
| 1777 |
(any_bitwise:SI (match_operand:SI 1 "register_operand" "%r,r") |
| 1778 |
(match_operand:SI 2 "arith_operand" " r,I")))] |
| 1779 |
"TARGET_64BIT" |
| 1780 |
"<insn>%i2\t%0,%1,%2" |
| 1781 |
[(set_attr "type" "logical") |
| 1782 |
(set_attr "mode" "SI")]) |
| 1783 |
|
| 1784 |
(define_insn "one_cmpl<mode>2" |
| 1785 |
[(set (match_operand:X 0 "register_operand" "=r") |
| 1786 |
(not:X (match_operand:X 1 "register_operand" " r")))] |
| 1787 |
"" |
| 1788 |
"not\t%0,%1" |
| 1789 |
[(set_attr "type" "logical") |
| 1790 |
(set_attr "mode" "<MODE>")]) |
| 1791 |
|
| 1792 |
(define_insn "*one_cmplsi2_internal" |
| 1793 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1794 |
(not:SI (match_operand:SI 1 "register_operand" " r")))] |
| 1795 |
"TARGET_64BIT" |
| 1796 |
"not\t%0,%1" |
| 1797 |
[(set_attr "type" "logical") |
| 1798 |
(set_attr "mode" "SI")]) |
| 1799 |
|
| 1800 |
;; |
| 1801 |
;; .................... |
| 1802 |
;; |
| 1803 |
;; TRUNCATION |
| 1804 |
;; |
| 1805 |
;; .................... |
| 1806 |
|
| 1807 |
(define_insn "truncdfsf2" |
| 1808 |
[(set (match_operand:SF 0 "register_operand" "=f") |
| 1809 |
(float_truncate:SF |
| 1810 |
(match_operand:DF 1 "register_operand" " f")))] |
| 1811 |
"TARGET_DOUBLE_FLOAT || TARGET_ZDINX" |
| 1812 |
"fcvt.s.d\t%0,%1" |
| 1813 |
[(set_attr "type" "fcvt") |
| 1814 |
(set_attr "mode" "SF")]) |
| 1815 |
|
| 1816 |
(define_insn "truncsfhf2" |
| 1817 |
[(set (match_operand:HF 0 "register_operand" "=f") |
| 1818 |
(float_truncate:HF |
| 1819 |
(match_operand:SF 1 "register_operand" " f")))] |
| 1820 |
"TARGET_ZFHMIN || TARGET_ZHINXMIN" |
| 1821 |
"fcvt.h.s\t%0,%1" |
| 1822 |
[(set_attr "type" "fcvt") |
| 1823 |
(set_attr "mode" "HF")]) |
| 1824 |
|
| 1825 |
(define_insn "truncdfhf2" |
| 1826 |
[(set (match_operand:HF 0 "register_operand" "=f") |
| 1827 |
(float_truncate:HF |
| 1828 |
(match_operand:DF 1 "register_operand" " f")))] |
| 1829 |
"(TARGET_ZFHMIN && TARGET_DOUBLE_FLOAT) || |
| 1830 |
(TARGET_ZHINXMIN && TARGET_ZDINX)" |
| 1831 |
"fcvt.h.d\t%0,%1" |
| 1832 |
[(set_attr "type" "fcvt") |
| 1833 |
(set_attr "mode" "HF")]) |
| 1834 |
|
| 1835 |
(define_insn "truncsfbf2" |
| 1836 |
[(set (match_operand:BF 0 "register_operand" "=f") |
| 1837 |
(float_truncate:BF |
| 1838 |
(match_operand:SF 1 "register_operand" " f")))] |
| 1839 |
"TARGET_ZFBFMIN" |
| 1840 |
"fcvt.bf16.s\t%0,%1" |
| 1841 |
[(set_attr "type" "fcvt") |
| 1842 |
(set_attr "mode" "BF")]) |
| 1843 |
|
| 1844 |
;; The conversion of HF/DF/TF to BF needs to be done with SF if there is a |
| 1845 |
;; chance to generate at least one instruction, otherwise just using |
| 1846 |
;; libfunc __trunc[h|d|t]fbf2. |
| 1847 |
(define_expand "trunc<mode>bf2" |
| 1848 |
[(set (match_operand:BF 0 "register_operand" "=f") |
| 1849 |
(float_truncate:BF |
| 1850 |
(match_operand:FBF 1 "register_operand" " f")))] |
| 1851 |
"TARGET_ZFBFMIN" |
| 1852 |
{ |
| 1853 |
convert_move (operands[0], |
| 1854 |
convert_modes (SFmode, <MODE>mode, operands[1], 0), 0); |
| 1855 |
DONE; |
| 1856 |
} |
| 1857 |
[(set_attr "type" "fcvt") |
| 1858 |
(set_attr "mode" "BF")]) |
| 1859 |
|
| 1860 |
;; |
| 1861 |
;; .................... |
| 1862 |
;; |
| 1863 |
;; ZERO EXTENSION |
| 1864 |
;; |
| 1865 |
;; .................... |
| 1866 |
|
| 1867 |
;; Extension insns. |
| 1868 |
|
| 1869 |
(define_expand "zero_extendsidi2" |
| 1870 |
[(set (match_operand:DI 0 "register_operand") |
| 1871 |
(zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))] |
| 1872 |
"TARGET_64BIT" |
| 1873 |
{ |
| 1874 |
if (SUBREG_P (operands[1]) && SUBREG_PROMOTED_VAR_P (operands[1]) |
| 1875 |
&& SUBREG_PROMOTED_UNSIGNED_P (operands[1])) |
| 1876 |
{ |
| 1877 |
emit_insn (gen_movdi (operands[0], SUBREG_REG (operands[1]))); |
| 1878 |
DONE; |
| 1879 |
} |
| 1880 |
}) |
| 1881 |
|
| 1882 |
(define_insn_and_split "*zero_extendsidi2_internal" |
| 1883 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 1884 |
(zero_extend:DI |
| 1885 |
(match_operand:SI 1 "nonimmediate_operand" " r,m")))] |
| 1886 |
"TARGET_64BIT && !TARGET_ZBA && !TARGET_XTHEADBB && !TARGET_XTHEADMEMIDX |
| 1887 |
&& !(REG_P (operands[1]) && VL_REG_P (REGNO (operands[1])))" |
| 1888 |
"@ |
| 1889 |
# |
| 1890 |
lwu\t%0,%1" |
| 1891 |
"&& reload_completed |
| 1892 |
&& REG_P (operands[1]) |
| 1893 |
&& !paradoxical_subreg_p (operands[0])" |
| 1894 |
[(set (match_dup 0) |
| 1895 |
(ashift:DI (match_dup 1) (const_int 32))) |
| 1896 |
(set (match_dup 0) |
| 1897 |
(lshiftrt:DI (match_dup 0) (const_int 32)))] |
| 1898 |
{ operands[1] = gen_lowpart (DImode, operands[1]); } |
| 1899 |
[(set_attr "move_type" "shift_shift,load") |
| 1900 |
(set_attr "type" "load") |
| 1901 |
(set_attr "mode" "DI")]) |
| 1902 |
|
| 1903 |
(define_expand "zero_extendhi<GPR:mode>2" |
| 1904 |
[(set (match_operand:GPR 0 "register_operand") |
| 1905 |
(zero_extend:GPR |
| 1906 |
(match_operand:HI 1 "nonimmediate_operand")))] |
| 1907 |
"") |
| 1908 |
|
| 1909 |
(define_insn_and_split "*zero_extendhi<GPR:mode>2" |
| 1910 |
[(set (match_operand:GPR 0 "register_operand" "=r,r") |
| 1911 |
(zero_extend:GPR |
| 1912 |
(match_operand:HI 1 "nonimmediate_operand" " r,m")))] |
| 1913 |
"!TARGET_ZBB && !TARGET_XTHEADBB && !TARGET_XTHEADMEMIDX" |
| 1914 |
"@ |
| 1915 |
# |
| 1916 |
lhu\t%0,%1" |
| 1917 |
"&& reload_completed |
| 1918 |
&& REG_P (operands[1]) |
| 1919 |
&& !paradoxical_subreg_p (operands[0])" |
| 1920 |
[(set (match_dup 0) |
| 1921 |
(ashift:GPR (match_dup 1) (match_dup 2))) |
| 1922 |
(set (match_dup 0) |
| 1923 |
(lshiftrt:GPR (match_dup 0) (match_dup 2)))] |
| 1924 |
{ |
| 1925 |
operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]); |
| 1926 |
operands[2] = GEN_INT(GET_MODE_BITSIZE(<GPR:MODE>mode) - 16); |
| 1927 |
} |
| 1928 |
[(set_attr "move_type" "shift_shift,load") |
| 1929 |
(set_attr "type" "load") |
| 1930 |
(set_attr "mode" "<GPR:MODE>")]) |
| 1931 |
|
| 1932 |
(define_expand "zero_extendqi<SUPERQI:mode>2" |
| 1933 |
[(set (match_operand:SUPERQI 0 "register_operand") |
| 1934 |
(zero_extend:SUPERQI |
| 1935 |
(match_operand:QI 1 "nonimmediate_operand")))] |
| 1936 |
"") |
| 1937 |
|
| 1938 |
(define_insn "*zero_extendqi<SUPERQI:mode>2_internal" |
| 1939 |
[(set (match_operand:SUPERQI 0 "register_operand" "=r,r") |
| 1940 |
(zero_extend:SUPERQI |
| 1941 |
(match_operand:QI 1 "nonimmediate_operand" " r,m")))] |
| 1942 |
"!TARGET_XTHEADMEMIDX" |
| 1943 |
"@ |
| 1944 |
andi\t%0,%1,0xff |
| 1945 |
lbu\t%0,%1" |
| 1946 |
[(set_attr "move_type" "andi,load") |
| 1947 |
(set_attr "type" "arith,load") |
| 1948 |
(set_attr "mode" "<SUPERQI:MODE>")]) |
| 1949 |
|
| 1950 |
;; |
| 1951 |
;; .................... |
| 1952 |
;; |
| 1953 |
;; SIGN EXTENSION |
| 1954 |
;; |
| 1955 |
;; .................... |
| 1956 |
|
| 1957 |
(define_expand "extendsidi2" |
| 1958 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 1959 |
(sign_extend:DI |
| 1960 |
(match_operand:SI 1 "nonimmediate_operand" " r,m")))] |
| 1961 |
"TARGET_64BIT" |
| 1962 |
{ |
| 1963 |
if (SUBREG_P (operands[1]) && SUBREG_PROMOTED_VAR_P (operands[1]) |
| 1964 |
&& SUBREG_PROMOTED_SIGNED_P (operands[1])) |
| 1965 |
{ |
| 1966 |
emit_insn (gen_movdi (operands[0], SUBREG_REG (operands[1]))); |
| 1967 |
DONE; |
| 1968 |
} |
| 1969 |
}) |
| 1970 |
|
| 1971 |
(define_insn "*extendsidi2_internal" |
| 1972 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 1973 |
(sign_extend:DI |
| 1974 |
(match_operand:SI 1 "nonimmediate_operand" " r,m")))] |
| 1975 |
"TARGET_64BIT && !TARGET_XTHEADMEMIDX" |
| 1976 |
"@ |
| 1977 |
sext.w\t%0,%1 |
| 1978 |
lw\t%0,%1" |
| 1979 |
[(set_attr "move_type" "move,load") |
| 1980 |
(set_attr "type" "move,load") |
| 1981 |
(set_attr "mode" "DI")]) |
| 1982 |
|
| 1983 |
(define_expand "extend<SHORT:mode><SUPERQI:mode>2" |
| 1984 |
[(set (match_operand:SUPERQI 0 "register_operand") |
| 1985 |
(sign_extend:SUPERQI (match_operand:SHORT 1 "nonimmediate_operand")))] |
| 1986 |
"") |
| 1987 |
|
| 1988 |
(define_insn_and_split "*extend<SHORT:mode><SUPERQI:mode>2" |
| 1989 |
[(set (match_operand:SUPERQI 0 "register_operand" "=r,r") |
| 1990 |
(sign_extend:SUPERQI |
| 1991 |
(match_operand:SHORT 1 "nonimmediate_operand" " r,m")))] |
| 1992 |
"!TARGET_ZBB && !TARGET_XTHEADBB && !TARGET_XTHEADMEMIDX" |
| 1993 |
"@ |
| 1994 |
# |
| 1995 |
l<SHORT:size>\t%0,%1" |
| 1996 |
"&& reload_completed |
| 1997 |
&& REG_P (operands[1]) |
| 1998 |
&& !paradoxical_subreg_p (operands[0])" |
| 1999 |
[(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2))) |
| 2000 |
(set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))] |
| 2001 |
{ |
| 2002 |
operands[0] = gen_lowpart (SImode, operands[0]); |
| 2003 |
operands[1] = gen_lowpart (SImode, operands[1]); |
| 2004 |
operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode) |
| 2005 |
- GET_MODE_BITSIZE (<SHORT:MODE>mode)); |
| 2006 |
} |
| 2007 |
[(set_attr "move_type" "shift_shift,load") |
| 2008 |
(set_attr "type" "load") |
| 2009 |
(set_attr "mode" "SI")]) |
| 2010 |
|
| 2011 |
(define_insn "extendhfsf2" |
| 2012 |
[(set (match_operand:SF 0 "register_operand" "=f") |
| 2013 |
(float_extend:SF |
| 2014 |
(match_operand:HF 1 "register_operand" " f")))] |
| 2015 |
"TARGET_ZFHMIN || TARGET_ZHINXMIN" |
| 2016 |
"fcvt.s.h\t%0,%1" |
| 2017 |
[(set_attr "type" "fcvt") |
| 2018 |
(set_attr "mode" "SF")]) |
| 2019 |
|
| 2020 |
(define_insn "extendbfsf2" |
| 2021 |
[(set (match_operand:SF 0 "register_operand" "=f") |
| 2022 |
(float_extend:SF |
| 2023 |
(match_operand:BF 1 "register_operand" " f")))] |
| 2024 |
"TARGET_ZFBFMIN" |
| 2025 |
"fcvt.s.bf16\t%0,%1" |
| 2026 |
[(set_attr "type" "fcvt") |
| 2027 |
(set_attr "mode" "SF")]) |
| 2028 |
|
| 2029 |
(define_insn "extendsfdf2" |
| 2030 |
[(set (match_operand:DF 0 "register_operand" "=f") |
| 2031 |
(float_extend:DF |
| 2032 |
(match_operand:SF 1 "register_operand" " f")))] |
| 2033 |
"TARGET_DOUBLE_FLOAT || TARGET_ZDINX" |
| 2034 |
"fcvt.d.s\t%0,%1" |
| 2035 |
[(set_attr "type" "fcvt") |
| 2036 |
(set_attr "mode" "DF")]) |
| 2037 |
|
| 2038 |
(define_insn "extendhfdf2" |
| 2039 |
[(set (match_operand:DF 0 "register_operand" "=f") |
| 2040 |
(float_extend:DF |
| 2041 |
(match_operand:HF 1 "register_operand" " f")))] |
| 2042 |
"(TARGET_ZFHMIN && TARGET_DOUBLE_FLOAT) || |
| 2043 |
(TARGET_ZHINXMIN && TARGET_ZDINX)" |
| 2044 |
"fcvt.d.h\t%0,%1" |
| 2045 |
[(set_attr "type" "fcvt") |
| 2046 |
(set_attr "mode" "DF")]) |
| 2047 |
|
| 2048 |
;; 16-bit floating point moves |
| 2049 |
(define_expand "mov<mode>" |
| 2050 |
[(set (match_operand:HFBF 0 "") |
| 2051 |
(match_operand:HFBF 1 ""))] |
| 2052 |
"" |
| 2053 |
{ |
| 2054 |
if (riscv_legitimize_move (<MODE>mode, operands[0], operands[1])) |
| 2055 |
DONE; |
| 2056 |
}) |
| 2057 |
|
| 2058 |
(define_insn "*mov<mode>_hardfloat" |
| 2059 |
[(set (match_operand:HFBF 0 "nonimmediate_operand" "=f, f,f,f,m,m,*f,*r, *r,*r,*m") |
| 2060 |
(match_operand:HFBF 1 "move_operand" " f,zfli,G,m,f,G,*r,*f,*G*r,*m,*r"))] |
| 2061 |
"((TARGET_ZFHMIN && <MODE>mode == HFmode) |
| 2062 |
|| (TARGET_ZFBFMIN && <MODE>mode == BFmode)) |
| 2063 |
&& (register_operand (operands[0], <MODE>mode) |
| 2064 |
|| reg_or_0_operand (operands[1], <MODE>mode))" |
| 2065 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2066 |
[(set_attr "move_type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2067 |
(set_attr "type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2068 |
(set_attr "mode" "<MODE>")]) |
| 2069 |
|
| 2070 |
(define_insn "*mov<mode>_softfloat" |
| 2071 |
[(set (match_operand:HFBF 0 "nonimmediate_operand" "=f, r,r,m,*f,*r") |
| 2072 |
(match_operand:HFBF 1 "move_operand" " f,Gr,m,r,*r,*f"))] |
| 2073 |
"((!TARGET_ZFHMIN && <MODE>mode == HFmode) || (<MODE>mode == BFmode)) |
| 2074 |
&& (register_operand (operands[0], <MODE>mode) |
| 2075 |
|| reg_or_0_operand (operands[1], <MODE>mode))" |
| 2076 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2077 |
[(set_attr "move_type" "fmove,move,load,store,mtc,mfc") |
| 2078 |
(set_attr "type" "fmove,move,load,store,mtc,mfc") |
| 2079 |
(set_attr "mode" "<MODE>")]) |
| 2080 |
|
| 2081 |
(define_insn "*mov<HFBF:mode>_softfloat_boxing" |
| 2082 |
[(set (match_operand:HFBF 0 "register_operand" "=f") |
| 2083 |
(unspec:HFBF [(match_operand:X 1 "register_operand" " r")] |
| 2084 |
UNSPEC_FMV_FP16_X))] |
| 2085 |
"!TARGET_ZFHMIN" |
| 2086 |
"fmv.w.x\t%0,%1" |
| 2087 |
[(set_attr "type" "fmove") |
| 2088 |
(set_attr "mode" "SF")]) |
| 2089 |
|
| 2090 |
;; |
| 2091 |
;; .................... |
| 2092 |
;; |
| 2093 |
;; CONVERSIONS |
| 2094 |
;; |
| 2095 |
;; .................... |
| 2096 |
|
| 2097 |
(define_expand "<fix_uns>_trunc<ANYF:mode>si2" |
| 2098 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 2099 |
(fix_ops:SI |
| 2100 |
(match_operand:ANYF 1 "register_operand" " f")))] |
| 2101 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2102 |
{ |
| 2103 |
if (TARGET_64BIT) |
| 2104 |
{ |
| 2105 |
rtx t = gen_reg_rtx (DImode); |
| 2106 |
emit_insn (gen_<fix_uns>_trunc<ANYF:mode>si2_sext (t, operands[1])); |
| 2107 |
t = gen_lowpart (SImode, t); |
| 2108 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 2109 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 2110 |
emit_move_insn (operands[0], t); |
| 2111 |
DONE; |
| 2112 |
} |
| 2113 |
}) |
| 2114 |
|
| 2115 |
(define_insn "*<fix_uns>_trunc<ANYF:mode>si2" |
| 2116 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 2117 |
(fix_ops:SI |
| 2118 |
(match_operand:ANYF 1 "register_operand" " f")))] |
| 2119 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2120 |
"fcvt.w<u>.<ANYF:fmt> %0,%1,rtz" |
| 2121 |
[(set_attr "type" "fcvt_f2i") |
| 2122 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2123 |
|
| 2124 |
(define_insn "<fix_uns>_trunc<ANYF:mode>si2_sext" |
| 2125 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 2126 |
(sign_extend:DI (fix_ops:SI |
| 2127 |
(match_operand:ANYF 1 "register_operand" " f"))))] |
| 2128 |
"TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)" |
| 2129 |
"fcvt.w<u>.<ANYF:fmt> %0,%1,rtz" |
| 2130 |
[(set_attr "type" "fcvt_f2i") |
| 2131 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2132 |
|
| 2133 |
(define_insn "<fix_uns>_trunc<ANYF:mode>di2" |
| 2134 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 2135 |
(fix_ops:DI |
| 2136 |
(match_operand:ANYF 1 "register_operand" " f")))] |
| 2137 |
"TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)" |
| 2138 |
"fcvt.l<u>.<ANYF:fmt> %0,%1,rtz" |
| 2139 |
[(set_attr "type" "fcvt_f2i") |
| 2140 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2141 |
|
| 2142 |
(define_insn "float<GPR:mode><ANYF:mode>2" |
| 2143 |
[(set (match_operand:ANYF 0 "register_operand" "= f") |
| 2144 |
(float:ANYF |
| 2145 |
(match_operand:GPR 1 "reg_or_0_operand" " rJ")))] |
| 2146 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2147 |
"fcvt.<ANYF:fmt>.<GPR:ifmt>\t%0,%z1" |
| 2148 |
[(set_attr "type" "fcvt_i2f") |
| 2149 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2150 |
|
| 2151 |
(define_insn "floatuns<GPR:mode><ANYF:mode>2" |
| 2152 |
[(set (match_operand:ANYF 0 "register_operand" "= f") |
| 2153 |
(unsigned_float:ANYF |
| 2154 |
(match_operand:GPR 1 "reg_or_0_operand" " rJ")))] |
| 2155 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2156 |
"fcvt.<ANYF:fmt>.<GPR:ifmt>u\t%0,%z1" |
| 2157 |
[(set_attr "type" "fcvt_i2f") |
| 2158 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2159 |
|
| 2160 |
(define_expand "lrint<ANYF:mode>si2" |
| 2161 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 2162 |
(unspec:SI |
| 2163 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2164 |
UNSPEC_LRINT))] |
| 2165 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2166 |
{ |
| 2167 |
if (TARGET_64BIT) |
| 2168 |
{ |
| 2169 |
rtx t = gen_reg_rtx (DImode); |
| 2170 |
emit_insn (gen_lrint<ANYF:mode>si2_sext (t, operands[1])); |
| 2171 |
t = gen_lowpart (SImode, t); |
| 2172 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 2173 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 2174 |
emit_move_insn (operands[0], t); |
| 2175 |
DONE; |
| 2176 |
} |
| 2177 |
}) |
| 2178 |
|
| 2179 |
(define_insn "*lrint<ANYF:mode>si2" |
| 2180 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 2181 |
(unspec:SI |
| 2182 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2183 |
UNSPEC_LRINT))] |
| 2184 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2185 |
"fcvt.w.<ANYF:fmt> %0,%1,dyn" |
| 2186 |
[(set_attr "type" "fcvt_f2i") |
| 2187 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2188 |
|
| 2189 |
(define_insn "lrint<ANYF:mode>si2_sext" |
| 2190 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 2191 |
(sign_extend:DI (unspec:SI |
| 2192 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2193 |
UNSPEC_LRINT)))] |
| 2194 |
"TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)" |
| 2195 |
"fcvt.w.<ANYF:fmt> %0,%1,dyn" |
| 2196 |
[(set_attr "type" "fcvt_f2i") |
| 2197 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2198 |
|
| 2199 |
(define_insn "lrint<ANYF:mode>di2" |
| 2200 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 2201 |
(unspec:DI |
| 2202 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2203 |
UNSPEC_LRINT))] |
| 2204 |
"TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)" |
| 2205 |
"fcvt.l.<ANYF:fmt> %0,%1,dyn" |
| 2206 |
[(set_attr "type" "fcvt_f2i") |
| 2207 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2208 |
|
| 2209 |
(define_expand "l<round_pattern><ANYF:mode>si2" |
| 2210 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 2211 |
(unspec:SI |
| 2212 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2213 |
ROUND))] |
| 2214 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2215 |
{ |
| 2216 |
if (TARGET_64BIT) |
| 2217 |
{ |
| 2218 |
rtx t = gen_reg_rtx (DImode); |
| 2219 |
emit_insn (gen_l<round_pattern><ANYF:mode>si2_sext (t, operands[1])); |
| 2220 |
t = gen_lowpart (SImode, t); |
| 2221 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 2222 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 2223 |
emit_move_insn (operands[0], t); |
| 2224 |
DONE; |
| 2225 |
} |
| 2226 |
}) |
| 2227 |
|
| 2228 |
(define_insn "*l<round_pattern><ANYF:mode>si2" |
| 2229 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 2230 |
(unspec:SI |
| 2231 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2232 |
ROUND))] |
| 2233 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 2234 |
"fcvt.w.<ANYF:fmt> %0,%1,<round_rm>" |
| 2235 |
[(set_attr "type" "fcvt_f2i") |
| 2236 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2237 |
|
| 2238 |
(define_insn "l<round_pattern><ANYF:mode>si2_sext" |
| 2239 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 2240 |
(sign_extend:DI (unspec:SI |
| 2241 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2242 |
ROUND)))] |
| 2243 |
"TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)" |
| 2244 |
"fcvt.w.<ANYF:fmt> %0,%1,<round_rm>" |
| 2245 |
[(set_attr "type" "fcvt_f2i") |
| 2246 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2247 |
|
| 2248 |
(define_insn "l<round_pattern><ANYF:mode>di2" |
| 2249 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 2250 |
(unspec:DI |
| 2251 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2252 |
ROUND))] |
| 2253 |
"TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)" |
| 2254 |
"fcvt.l.<ANYF:fmt> %0,%1,<round_rm>" |
| 2255 |
[(set_attr "type" "fcvt_f2i") |
| 2256 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2257 |
|
| 2258 |
;; There are a couple non-obvious restrictions to be aware of. |
| 2259 |
;; |
| 2260 |
;; We'll do a FP-INT conversion in the sequence. But we don't |
| 2261 |
;; have a .l (64bit) variant of those instructions for rv32. |
| 2262 |
;; To preserve proper semantics we must reject DFmode inputs |
| 2263 |
;; for rv32 unless Zfa is enabled. |
| 2264 |
;; |
| 2265 |
;; The ANYF iterator allows HFmode. We don't have all the |
| 2266 |
;; necessary patterns defined for HFmode. So restrict HFmode |
| 2267 |
;; to TARGET_ZFA. |
| 2268 |
(define_expand "<round_pattern><ANYF:mode>2" |
| 2269 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 2270 |
(unspec:ANYF |
| 2271 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2272 |
ROUND))] |
| 2273 |
"(TARGET_HARD_FLOAT |
| 2274 |
&& (TARGET_ZFA || flag_fp_int_builtin_inexact || !flag_trapping_math) |
| 2275 |
&& (TARGET_ZFA || TARGET_64BIT || <ANYF:MODE>mode != DFmode) |
| 2276 |
&& (TARGET_ZFA || <ANYF:MODE>mode != HFmode))" |
| 2277 |
{ |
| 2278 |
if (TARGET_ZFA) |
| 2279 |
emit_insn (gen_<round_pattern><ANYF:mode>_zfa2 (operands[0], |
| 2280 |
operands[1])); |
| 2281 |
else |
| 2282 |
{ |
| 2283 |
rtx reg; |
| 2284 |
rtx label1 = gen_label_rtx (); |
| 2285 |
rtx label2 = gen_label_rtx (); |
| 2286 |
rtx label3 = gen_label_rtx (); |
| 2287 |
rtx end_label = gen_label_rtx (); |
| 2288 |
rtx abs_reg = gen_reg_rtx (<ANYF:MODE>mode); |
| 2289 |
rtx coeff_reg = gen_reg_rtx (<ANYF:MODE>mode); |
| 2290 |
rtx tmp_reg = gen_reg_rtx (<ANYF:MODE>mode); |
| 2291 |
|
| 2292 |
riscv_emit_move (tmp_reg, operands[1]); |
| 2293 |
|
| 2294 |
if (flag_trapping_math) |
| 2295 |
{ |
| 2296 |
/* Check if the input is a NaN. */ |
| 2297 |
riscv_expand_conditional_branch (label1, EQ, |
| 2298 |
operands[1], operands[1]); |
| 2299 |
|
| 2300 |
emit_jump_insn (gen_jump (label3)); |
| 2301 |
emit_barrier (); |
| 2302 |
|
| 2303 |
emit_label (label1); |
| 2304 |
} |
| 2305 |
|
| 2306 |
riscv_emit_move (coeff_reg, |
| 2307 |
riscv_vector::get_fp_rounding_coefficient (<ANYF:MODE>mode)); |
| 2308 |
emit_insn (gen_abs<ANYF:mode>2 (abs_reg, operands[1])); |
| 2309 |
|
| 2310 |
riscv_expand_conditional_branch (label2, LT, abs_reg, coeff_reg); |
| 2311 |
|
| 2312 |
emit_jump_insn (gen_jump (end_label)); |
| 2313 |
emit_barrier (); |
| 2314 |
|
| 2315 |
emit_label (label2); |
| 2316 |
switch (<ANYF:MODE>mode) |
| 2317 |
{ |
| 2318 |
case SFmode: |
| 2319 |
reg = gen_reg_rtx (SImode); |
| 2320 |
emit_insn (gen_l<round_pattern>sfsi2 (reg, operands[1])); |
| 2321 |
emit_insn (gen_floatsisf2 (abs_reg, reg)); |
| 2322 |
break; |
| 2323 |
case DFmode: |
| 2324 |
reg = gen_reg_rtx (DImode); |
| 2325 |
emit_insn (gen_l<round_pattern>dfdi2 (reg, operands[1])); |
| 2326 |
emit_insn (gen_floatdidf2 (abs_reg, reg)); |
| 2327 |
break; |
| 2328 |
default: |
| 2329 |
gcc_unreachable (); |
| 2330 |
} |
| 2331 |
|
| 2332 |
emit_insn (gen_copysign<ANYF:mode>3 (tmp_reg, abs_reg, operands[1])); |
| 2333 |
|
| 2334 |
emit_jump_insn (gen_jump (end_label)); |
| 2335 |
emit_barrier (); |
| 2336 |
|
| 2337 |
if (flag_trapping_math) |
| 2338 |
{ |
| 2339 |
emit_label (label3); |
| 2340 |
/* Generate a qNaN from an sNaN if needed. */ |
| 2341 |
emit_insn (gen_add<ANYF:mode>3 (tmp_reg, operands[1], operands[1])); |
| 2342 |
} |
| 2343 |
|
| 2344 |
emit_label (end_label); |
| 2345 |
riscv_emit_move (operands[0], tmp_reg); |
| 2346 |
} |
| 2347 |
|
| 2348 |
DONE; |
| 2349 |
}) |
| 2350 |
|
| 2351 |
(define_insn "<round_pattern><ANYF:mode>_zfa2" |
| 2352 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 2353 |
(unspec:ANYF |
| 2354 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2355 |
ROUND))] |
| 2356 |
"TARGET_HARD_FLOAT && TARGET_ZFA" |
| 2357 |
"fround.<ANYF:fmt>\t%0,%1,<round_rm>" |
| 2358 |
[(set_attr "type" "fcvt") |
| 2359 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2360 |
|
| 2361 |
(define_insn "rint<ANYF:mode>2" |
| 2362 |
[(set (match_operand:ANYF 0 "register_operand" "=f") |
| 2363 |
(unspec:ANYF |
| 2364 |
[(match_operand:ANYF 1 "register_operand" " f")] |
| 2365 |
UNSPEC_RINT))] |
| 2366 |
"TARGET_HARD_FLOAT && TARGET_ZFA" |
| 2367 |
"froundnx.<ANYF:fmt>\t%0,%1" |
| 2368 |
[(set_attr "type" "fcvt") |
| 2369 |
(set_attr "mode" "<ANYF:MODE>")]) |
| 2370 |
|
| 2371 |
;; |
| 2372 |
;; .................... |
| 2373 |
;; |
| 2374 |
;; DATA MOVEMENT |
| 2375 |
;; |
| 2376 |
;; .................... |
| 2377 |
|
| 2378 |
;; Lower-level instructions for loading an address from the GOT. |
| 2379 |
;; We could use MEMs, but an unspec gives more optimization |
| 2380 |
;; opportunities. |
| 2381 |
|
| 2382 |
(define_insn "got_load<mode>" |
| 2383 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 2384 |
(unspec:P |
| 2385 |
[(match_operand:P 1 "symbolic_operand" "")] |
| 2386 |
UNSPEC_LOAD_GOT))] |
| 2387 |
"" |
| 2388 |
"la\t%0,%1" |
| 2389 |
[(set_attr "got" "load") |
| 2390 |
(set_attr "type" "load") |
| 2391 |
(set_attr "mode" "<MODE>")]) |
| 2392 |
|
| 2393 |
(define_insn "tls_add_tp_le<mode>" |
| 2394 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 2395 |
(unspec:P |
| 2396 |
[(match_operand:P 1 "register_operand" "r") |
| 2397 |
(match_operand:P 2 "register_operand" "r") |
| 2398 |
(match_operand:P 3 "symbolic_operand" "")] |
| 2399 |
UNSPEC_TLS_LE))] |
| 2400 |
"" |
| 2401 |
"add\t%0,%1,%2,%%tprel_add(%3)" |
| 2402 |
[(set_attr "type" "arith") |
| 2403 |
(set_attr "mode" "<MODE>")]) |
| 2404 |
|
| 2405 |
(define_insn "got_load_tls_gd<mode>" |
| 2406 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 2407 |
(unspec:P |
| 2408 |
[(match_operand:P 1 "symbolic_operand" "")] |
| 2409 |
UNSPEC_TLS_GD))] |
| 2410 |
"" |
| 2411 |
"la.tls.gd\t%0,%1" |
| 2412 |
[(set_attr "got" "load") |
| 2413 |
(set_attr "type" "load") |
| 2414 |
(set_attr "mode" "<MODE>")]) |
| 2415 |
|
| 2416 |
(define_insn "got_load_tls_ie<mode>" |
| 2417 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 2418 |
(unspec:P |
| 2419 |
[(match_operand:P 1 "symbolic_operand" "")] |
| 2420 |
UNSPEC_TLS_IE))] |
| 2421 |
"" |
| 2422 |
"la.tls.ie\t%0,%1" |
| 2423 |
[(set_attr "got" "load") |
| 2424 |
(set_attr "type" "load") |
| 2425 |
(set_attr "mode" "<MODE>")]) |
| 2426 |
|
| 2427 |
(define_insn "@tlsdesc<mode>" |
| 2428 |
[(set (reg:P A0_REGNUM) |
| 2429 |
(unspec:P |
| 2430 |
[(match_operand:P 0 "symbolic_operand" "")] |
| 2431 |
UNSPEC_TLSDESC)) |
| 2432 |
(clobber (reg:P T0_REGNUM))] |
| 2433 |
"TARGET_TLSDESC" |
| 2434 |
{ |
| 2435 |
return ".LT%=: auipc\ta0,%%tlsdesc_hi(%0)\;" |
| 2436 |
"<load>\tt0,%%tlsdesc_load_lo(.LT%=)(a0)\;" |
| 2437 |
"addi\ta0,a0,%%tlsdesc_add_lo(.LT%=)\;" |
| 2438 |
"jalr\tt0,t0,%%tlsdesc_call(.LT%=)"; |
| 2439 |
} |
| 2440 |
[(set_attr "type" "multi") |
| 2441 |
(set_attr "length" "16") |
| 2442 |
(set_attr "mode" "<MODE>")]) |
| 2443 |
|
| 2444 |
(define_insn "auipc<mode>" |
| 2445 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 2446 |
(unspec:P |
| 2447 |
[(match_operand:P 1 "symbolic_operand" "") |
| 2448 |
(match_operand:P 2 "const_int_operand") |
| 2449 |
(pc)] |
| 2450 |
UNSPEC_AUIPC))] |
| 2451 |
"" |
| 2452 |
".LA%2: auipc\t%0,%h1" |
| 2453 |
[(set_attr "type" "auipc") |
| 2454 |
(set_attr "cannot_copy" "yes")]) |
| 2455 |
|
| 2456 |
;; Instructions for adding the low 12 bits of an address to a register. |
| 2457 |
;; Operand 2 is the address: riscv_print_operand works out which relocation |
| 2458 |
;; should be applied. |
| 2459 |
|
| 2460 |
(define_insn "*low<mode>" |
| 2461 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 2462 |
(lo_sum:P (match_operand:P 1 "register_operand" " r") |
| 2463 |
(match_operand:P 2 "symbolic_operand" "")))] |
| 2464 |
"" |
| 2465 |
"addi\t%0,%1,%R2" |
| 2466 |
[(set_attr "type" "arith") |
| 2467 |
(set_attr "mode" "<MODE>")]) |
| 2468 |
|
| 2469 |
;; Allow combine to split complex const_int load sequences, using operand 2 |
| 2470 |
;; to store the intermediate results. See move_operand for details. |
| 2471 |
(define_split |
| 2472 |
[(set (match_operand:GPR 0 "register_operand") |
| 2473 |
(match_operand:GPR 1 "splittable_const_int_operand")) |
| 2474 |
(clobber (match_operand:GPR 2 "register_operand"))] |
| 2475 |
"" |
| 2476 |
[(const_int 0)] |
| 2477 |
{ |
| 2478 |
riscv_move_integer (operands[2], operands[0], INTVAL (operands[1]), |
| 2479 |
<GPR:MODE>mode); |
| 2480 |
DONE; |
| 2481 |
}) |
| 2482 |
|
| 2483 |
;; Likewise, for symbolic operands. |
| 2484 |
(define_split |
| 2485 |
[(set (match_operand:P 0 "register_operand") |
| 2486 |
(match_operand:P 1)) |
| 2487 |
(clobber (match_operand:P 2 "register_operand"))] |
| 2488 |
"riscv_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)" |
| 2489 |
[(set (match_dup 0) (match_dup 3))] |
| 2490 |
{ |
| 2491 |
riscv_split_symbol (operands[2], operands[1], |
| 2492 |
MAX_MACHINE_MODE, &operands[3]); |
| 2493 |
}) |
| 2494 |
|
| 2495 |
;; Pretend to have the ability to load complex const_int in order to get |
| 2496 |
;; better code generation around them. |
| 2497 |
;; But avoid constants that are special cased elsewhere. |
| 2498 |
;; |
| 2499 |
;; Hide it from IRA register equiv recog* () to elide potential undoing of split |
| 2500 |
;; |
| 2501 |
(define_insn_and_split "*mvconst_internal" |
| 2502 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 2503 |
(match_operand:GPR 1 "splittable_const_int_operand" "i"))] |
| 2504 |
"!ira_in_progress |
| 2505 |
&& !(p2m1_shift_operand (operands[1], <MODE>mode) |
| 2506 |
|| high_mask_shift_operand (operands[1], <MODE>mode) |
| 2507 |
|| exact_log2 (INTVAL (operands[1])) >= 0)" |
| 2508 |
"#" |
| 2509 |
"&& 1" |
| 2510 |
[(const_int 0)] |
| 2511 |
{ |
| 2512 |
riscv_move_integer (operands[0], operands[0], INTVAL (operands[1]), |
| 2513 |
<MODE>mode); |
| 2514 |
DONE; |
| 2515 |
} |
| 2516 |
[(set_attr "type" "move")]) |
| 2517 |
|
| 2518 |
;; 64-bit integer moves |
| 2519 |
|
| 2520 |
(define_expand "movdi" |
| 2521 |
[(set (match_operand:DI 0 "") |
| 2522 |
(match_operand:DI 1 ""))] |
| 2523 |
"" |
| 2524 |
{ |
| 2525 |
if (riscv_legitimize_move (DImode, operands[0], operands[1])) |
| 2526 |
DONE; |
| 2527 |
}) |
| 2528 |
|
| 2529 |
(define_insn "*movdi_32bit" |
| 2530 |
[(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,m, *f,*f,*r,*f,*m,r") |
| 2531 |
(match_operand:DI 1 "move_operand" " r,i,m,r,*J*r,*m,*f,*f,*f,vp"))] |
| 2532 |
"!TARGET_64BIT |
| 2533 |
&& (register_operand (operands[0], DImode) |
| 2534 |
|| reg_or_0_operand (operands[1], DImode))" |
| 2535 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2536 |
[(set_attr "move_type" "move,const,load,store,mtc,fpload,mfc,fmove,fpstore,rdvlenb") |
| 2537 |
(set_attr "mode" "DI") |
| 2538 |
(set_attr "type" "move,move,load,store,move,fpload,move,fmove,fpstore,move") |
| 2539 |
(set_attr "ext" "base,base,base,base,d,d,d,d,d,vector")]) |
| 2540 |
|
| 2541 |
(define_insn "*movdi_64bit" |
| 2542 |
[(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r, m, *f,*f,*r,*f,*m,r") |
| 2543 |
(match_operand:DI 1 "move_operand" " r,T,m,rJ,*r*J,*m,*f,*f,*f,vp"))] |
| 2544 |
"TARGET_64BIT |
| 2545 |
&& (register_operand (operands[0], DImode) |
| 2546 |
|| reg_or_0_operand (operands[1], DImode))" |
| 2547 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2548 |
[(set_attr "move_type" "move,const,load,store,mtc,fpload,mfc,fmove,fpstore,rdvlenb") |
| 2549 |
(set_attr "mode" "DI") |
| 2550 |
(set_attr "type" "move,move,load,store,mtc,fpload,mfc,fmove,fpstore,move") |
| 2551 |
(set_attr "ext" "base,base,base,base,d,d,d,d,d,vector")]) |
| 2552 |
|
| 2553 |
;; 32-bit Integer moves |
| 2554 |
|
| 2555 |
(define_expand "mov<mode>" |
| 2556 |
[(set (match_operand:MOVE32 0 "") |
| 2557 |
(match_operand:MOVE32 1 ""))] |
| 2558 |
"" |
| 2559 |
{ |
| 2560 |
if (riscv_legitimize_move (<MODE>mode, operands[0], operands[1])) |
| 2561 |
DONE; |
| 2562 |
}) |
| 2563 |
|
| 2564 |
(define_insn "*movsi_internal" |
| 2565 |
[(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r, m, *f,*f,*r,*m,r") |
| 2566 |
(match_operand:SI 1 "move_operand" " r,T,m,rJ,*r*J,*m,*f,*f,vp"))] |
| 2567 |
"(register_operand (operands[0], SImode) |
| 2568 |
|| reg_or_0_operand (operands[1], SImode)) |
| 2569 |
&& !(REG_P (operands[1]) && VL_REG_P (REGNO (operands[1])))" |
| 2570 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2571 |
[(set_attr "move_type" "move,const,load,store,mtc,fpload,mfc,fpstore,rdvlenb") |
| 2572 |
(set_attr "mode" "SI") |
| 2573 |
(set_attr "type" "move,move,load,store,mtc,fpload,mfc,fpstore,move") |
| 2574 |
(set_attr "ext" "base,base,base,base,f,f,f,f,vector")]) |
| 2575 |
|
| 2576 |
;; 16-bit Integer moves |
| 2577 |
|
| 2578 |
;; Unlike most other insns, the move insns can't be split with |
| 2579 |
;; different predicates, because register spilling and other parts of |
| 2580 |
;; the compiler, have memoized the insn number already. |
| 2581 |
;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND. |
| 2582 |
|
| 2583 |
(define_expand "movhi" |
| 2584 |
[(set (match_operand:HI 0 "") |
| 2585 |
(match_operand:HI 1 ""))] |
| 2586 |
"" |
| 2587 |
{ |
| 2588 |
if (riscv_legitimize_move (HImode, operands[0], operands[1])) |
| 2589 |
DONE; |
| 2590 |
}) |
| 2591 |
|
| 2592 |
(define_insn "*movhi_internal" |
| 2593 |
[(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r, m, *f,*r,r") |
| 2594 |
(match_operand:HI 1 "move_operand" " r,T,m,rJ,*r*J,*f,vp"))] |
| 2595 |
"(register_operand (operands[0], HImode) |
| 2596 |
|| reg_or_0_operand (operands[1], HImode))" |
| 2597 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2598 |
[(set_attr "move_type" "move,const,load,store,mtc,mfc,rdvlenb") |
| 2599 |
(set_attr "mode" "HI") |
| 2600 |
(set_attr "type" "move,move,load,store,mtc,mfc,move") |
| 2601 |
(set_attr "ext" "base,base,base,base,f,f,vector")]) |
| 2602 |
|
| 2603 |
;; HImode constant generation; see riscv_move_integer for details. |
| 2604 |
;; si+si->hi without truncation is legal because of |
| 2605 |
;; TARGET_TRULY_NOOP_TRUNCATION. |
| 2606 |
|
| 2607 |
(define_insn "*add<mode>hi3" |
| 2608 |
[(set (match_operand:HI 0 "register_operand" "=r,r") |
| 2609 |
(plus:HI (match_operand:HISI 1 "register_operand" " r,r") |
| 2610 |
(match_operand:HISI 2 "arith_operand" " r,I")))] |
| 2611 |
"" |
| 2612 |
"add%i2%~\t%0,%1,%2" |
| 2613 |
[(set_attr "type" "arith") |
| 2614 |
(set_attr "mode" "HI")]) |
| 2615 |
|
| 2616 |
(define_insn "*xor<mode>hi3" |
| 2617 |
[(set (match_operand:HI 0 "register_operand" "=r,r") |
| 2618 |
(xor:HI (match_operand:HISI 1 "register_operand" " r,r") |
| 2619 |
(match_operand:HISI 2 "arith_operand" " r,I")))] |
| 2620 |
"" |
| 2621 |
"xor%i2\t%0,%1,%2" |
| 2622 |
[(set_attr "type" "logical") |
| 2623 |
(set_attr "mode" "HI")]) |
| 2624 |
|
| 2625 |
;; 8-bit Integer moves |
| 2626 |
|
| 2627 |
(define_expand "movqi" |
| 2628 |
[(set (match_operand:QI 0 "") |
| 2629 |
(match_operand:QI 1 ""))] |
| 2630 |
"" |
| 2631 |
{ |
| 2632 |
if (riscv_legitimize_move (QImode, operands[0], operands[1])) |
| 2633 |
DONE; |
| 2634 |
}) |
| 2635 |
|
| 2636 |
(define_insn "*movqi_internal" |
| 2637 |
[(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,r, m, *f,*r,r") |
| 2638 |
(match_operand:QI 1 "move_operand" " r,I,m,rJ,*r*J,*f,vp"))] |
| 2639 |
"(register_operand (operands[0], QImode) |
| 2640 |
|| reg_or_0_operand (operands[1], QImode))" |
| 2641 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2642 |
[(set_attr "move_type" "move,const,load,store,mtc,mfc,rdvlenb") |
| 2643 |
(set_attr "mode" "QI") |
| 2644 |
(set_attr "type" "move,move,load,store,mtc,mfc,move") |
| 2645 |
(set_attr "ext" "base,base,base,base,f,f,vector")]) |
| 2646 |
|
| 2647 |
;; 32-bit floating point moves |
| 2648 |
|
| 2649 |
(define_expand "movsf" |
| 2650 |
[(set (match_operand:SF 0 "") |
| 2651 |
(match_operand:SF 1 ""))] |
| 2652 |
"" |
| 2653 |
{ |
| 2654 |
if (riscv_legitimize_move (SFmode, operands[0], operands[1])) |
| 2655 |
DONE; |
| 2656 |
}) |
| 2657 |
|
| 2658 |
(define_insn "*movsf_hardfloat" |
| 2659 |
[(set (match_operand:SF 0 "nonimmediate_operand" "=f, f,f,f,m,m,*f,*r, *r,*r,*m") |
| 2660 |
(match_operand:SF 1 "move_operand" " f,zfli,G,m,f,G,*r,*f,*G*r,*m,*r"))] |
| 2661 |
"TARGET_HARD_FLOAT |
| 2662 |
&& (register_operand (operands[0], SFmode) |
| 2663 |
|| reg_or_0_operand (operands[1], SFmode))" |
| 2664 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2665 |
[(set_attr "move_type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2666 |
(set_attr "type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2667 |
(set_attr "mode" "SF")]) |
| 2668 |
|
| 2669 |
(define_insn "*movsf_softfloat" |
| 2670 |
[(set (match_operand:SF 0 "nonimmediate_operand" "= r,r,m") |
| 2671 |
(match_operand:SF 1 "move_operand" " Gr,m,r"))] |
| 2672 |
"!TARGET_HARD_FLOAT |
| 2673 |
&& (register_operand (operands[0], SFmode) |
| 2674 |
|| reg_or_0_operand (operands[1], SFmode))" |
| 2675 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2676 |
[(set_attr "move_type" "move,load,store") |
| 2677 |
(set_attr "type" "move,load,store") |
| 2678 |
(set_attr "mode" "SF")]) |
| 2679 |
|
| 2680 |
;; 64-bit floating point moves |
| 2681 |
|
| 2682 |
(define_expand "movdf" |
| 2683 |
[(set (match_operand:DF 0 "") |
| 2684 |
(match_operand:DF 1 ""))] |
| 2685 |
"" |
| 2686 |
{ |
| 2687 |
if (riscv_legitimize_move (DFmode, operands[0], operands[1])) |
| 2688 |
DONE; |
| 2689 |
}) |
| 2690 |
|
| 2691 |
|
| 2692 |
;; In RV32, we lack fmv.x.d and fmv.d.x. Go through memory instead. |
| 2693 |
;; (However, we can still use fcvt.d.w to zero a floating-point register.) |
| 2694 |
(define_insn "*movdf_hardfloat_rv32" |
| 2695 |
[(set (match_operand:DF 0 "nonimmediate_operand" "=f, f,f,f,m,m,*zmvf,*zmvr, *r,*r,*th_m_noi") |
| 2696 |
(match_operand:DF 1 "move_operand" " f,zfli,G,m,f,G,*zmvr,*zmvf,*r*G,*th_m_noi,*r"))] |
| 2697 |
"!TARGET_64BIT && TARGET_DOUBLE_FLOAT |
| 2698 |
&& (register_operand (operands[0], DFmode) |
| 2699 |
|| reg_or_0_operand (operands[1], DFmode))" |
| 2700 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2701 |
[(set_attr "move_type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2702 |
(set_attr "type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2703 |
(set_attr "mode" "DF")]) |
| 2704 |
|
| 2705 |
(define_insn "*movdf_hardfloat_rv64" |
| 2706 |
[(set (match_operand:DF 0 "nonimmediate_operand" "=f, f,f,f,m,m,*f,*r, *r,*r,*m") |
| 2707 |
(match_operand:DF 1 "move_operand" " f,zfli,G,m,f,G,*r,*f,*r*G,*m,*r"))] |
| 2708 |
"TARGET_64BIT && TARGET_DOUBLE_FLOAT |
| 2709 |
&& (register_operand (operands[0], DFmode) |
| 2710 |
|| reg_or_0_operand (operands[1], DFmode))" |
| 2711 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2712 |
[(set_attr "move_type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2713 |
(set_attr "type" "fmove,fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") |
| 2714 |
(set_attr "mode" "DF")]) |
| 2715 |
|
| 2716 |
(define_insn "*movdf_softfloat" |
| 2717 |
[(set (match_operand:DF 0 "nonimmediate_operand" "= r,r, m") |
| 2718 |
(match_operand:DF 1 "move_operand" " rG,m,rG"))] |
| 2719 |
"!TARGET_DOUBLE_FLOAT |
| 2720 |
&& (register_operand (operands[0], DFmode) |
| 2721 |
|| reg_or_0_operand (operands[1], DFmode))" |
| 2722 |
{ return riscv_output_move (operands[0], operands[1]); } |
| 2723 |
[(set_attr "move_type" "move,load,store") |
| 2724 |
(set_attr "type" "fmove,fpload,fpstore") |
| 2725 |
(set_attr "mode" "DF")]) |
| 2726 |
|
| 2727 |
(define_insn "movsidf2_low_rv32" |
| 2728 |
[(set (match_operand:SI 0 "register_operand" "= r") |
| 2729 |
(unspec:SI |
| 2730 |
[(match_operand:DF 1 "register_operand" "zmvf")] |
| 2731 |
UNSPEC_FMV_X_W))] |
| 2732 |
"TARGET_HARD_FLOAT && !TARGET_64BIT && TARGET_ZFA" |
| 2733 |
"fmv.x.w\t%0,%1" |
| 2734 |
[(set_attr "move_type" "fmove") |
| 2735 |
(set_attr "type" "fmove") |
| 2736 |
(set_attr "mode" "DF")]) |
| 2737 |
|
| 2738 |
|
| 2739 |
(define_insn "movsidf2_high_rv32" |
| 2740 |
[(set (match_operand:SI 0 "register_operand" "= r") |
| 2741 |
(unspec:SI |
| 2742 |
[(match_operand:DF 1 "register_operand" "zmvf")] |
| 2743 |
UNSPEC_FMVH_X_D))] |
| 2744 |
"TARGET_HARD_FLOAT && !TARGET_64BIT && TARGET_ZFA" |
| 2745 |
"fmvh.x.d\t%0,%1" |
| 2746 |
[(set_attr "move_type" "fmove") |
| 2747 |
(set_attr "type" "fmove") |
| 2748 |
(set_attr "mode" "DF")]) |
| 2749 |
|
| 2750 |
(define_insn "movdfsisi3_rv32" |
| 2751 |
[(set (match_operand:DF 0 "register_operand" "= f") |
| 2752 |
(plus:DF |
| 2753 |
(match_operand:SI 2 "register_operand" "zmvr") |
| 2754 |
(ashift:SI |
| 2755 |
(match_operand:SI 1 "register_operand" "zmvr") |
| 2756 |
(const_int 32))))] |
| 2757 |
"TARGET_HARD_FLOAT && !TARGET_64BIT && TARGET_ZFA" |
| 2758 |
"fmvp.d.x\t%0,%2,%1" |
| 2759 |
[(set_attr "move_type" "fmove") |
| 2760 |
(set_attr "type" "fmove") |
| 2761 |
(set_attr "mode" "DF")]) |
| 2762 |
|
| 2763 |
(define_split |
| 2764 |
[(set (match_operand:MOVE64 0 "nonimmediate_operand") |
| 2765 |
(match_operand:MOVE64 1 "move_operand"))] |
| 2766 |
"reload_completed |
| 2767 |
&& riscv_split_64bit_move_p (operands[0], operands[1])" |
| 2768 |
[(const_int 0)] |
| 2769 |
{ |
| 2770 |
riscv_split_doubleword_move (operands[0], operands[1]); |
| 2771 |
DONE; |
| 2772 |
}) |
| 2773 |
|
| 2774 |
(define_expand "cmpmemsi" |
| 2775 |
[(parallel [(set (match_operand:SI 0) |
| 2776 |
(compare:SI (match_operand:BLK 1) |
| 2777 |
(match_operand:BLK 2))) |
| 2778 |
(use (match_operand:SI 3)) |
| 2779 |
(use (match_operand:SI 4))])] |
| 2780 |
"!optimize_size" |
| 2781 |
{ |
| 2782 |
/* If TARGET_VECTOR is false, this routine will return false and we will |
| 2783 |
try scalar expansion. */ |
| 2784 |
if (riscv_vector::expand_vec_cmpmem (operands[0], operands[1], |
| 2785 |
operands[2], operands[3])) |
| 2786 |
DONE; |
| 2787 |
|
| 2788 |
rtx temp = gen_reg_rtx (word_mode); |
| 2789 |
if (riscv_expand_block_compare (temp, operands[1], operands[2], |
| 2790 |
operands[3])) |
| 2791 |
{ |
| 2792 |
if (TARGET_64BIT) |
| 2793 |
{ |
| 2794 |
temp = gen_lowpart (SImode, temp); |
| 2795 |
SUBREG_PROMOTED_VAR_P (temp) = 1; |
| 2796 |
SUBREG_PROMOTED_SET (temp, SRP_SIGNED); |
| 2797 |
} |
| 2798 |
emit_move_insn (operands[0], temp); |
| 2799 |
DONE; |
| 2800 |
} |
| 2801 |
else |
| 2802 |
FAIL; |
| 2803 |
}) |
| 2804 |
|
| 2805 |
(define_expand "cpymem<mode>" |
| 2806 |
[(parallel [(set (match_operand:BLK 0 "general_operand") |
| 2807 |
(match_operand:BLK 1 "general_operand")) |
| 2808 |
(use (match_operand:P 2 "")) |
| 2809 |
(use (match_operand:SI 3 "const_int_operand"))])] |
| 2810 |
"" |
| 2811 |
{ |
| 2812 |
if (riscv_expand_block_move (operands[0], operands[1], operands[2])) |
| 2813 |
DONE; |
| 2814 |
else |
| 2815 |
FAIL; |
| 2816 |
}) |
| 2817 |
|
| 2818 |
;; Fill memory with constant byte. |
| 2819 |
;; Argument 0 is the destination |
| 2820 |
;; Argument 1 is the constant byte |
| 2821 |
;; Argument 2 is the length |
| 2822 |
;; Argument 3 is the alignment |
| 2823 |
|
| 2824 |
(define_expand "setmem<mode>" |
| 2825 |
[(parallel [(set (match_operand:BLK 0 "memory_operand") |
| 2826 |
(match_operand:QI 2 "nonmemory_operand")) |
| 2827 |
(use (match_operand:P 1 "")) |
| 2828 |
(use (match_operand:SI 3 "const_int_operand"))])] |
| 2829 |
"" |
| 2830 |
{ |
| 2831 |
/* If TARGET_VECTOR is false, this routine will return false and we will |
| 2832 |
try scalar expansion. */ |
| 2833 |
if (riscv_vector::expand_vec_setmem (operands[0], operands[1], operands[2])) |
| 2834 |
DONE; |
| 2835 |
|
| 2836 |
/* If value to set is not zero, use the library routine. */ |
| 2837 |
if (operands[2] != const0_rtx) |
| 2838 |
FAIL; |
| 2839 |
|
| 2840 |
if (riscv_expand_block_clear (operands[0], operands[1])) |
| 2841 |
DONE; |
| 2842 |
else |
| 2843 |
FAIL; |
| 2844 |
}) |
| 2845 |
|
| 2846 |
(define_expand "movmem<mode>" |
| 2847 |
[(parallel [(set (match_operand:BLK 0 "general_operand") |
| 2848 |
(match_operand:BLK 1 "general_operand")) |
| 2849 |
(use (match_operand:P 2 "const_int_operand")) |
| 2850 |
(use (match_operand:SI 3 "const_int_operand"))])] |
| 2851 |
"TARGET_VECTOR" |
| 2852 |
{ |
| 2853 |
if (riscv_vector::expand_block_move (operands[0], operands[1], operands[2], |
| 2854 |
true)) |
| 2855 |
DONE; |
| 2856 |
else |
| 2857 |
FAIL; |
| 2858 |
}) |
| 2859 |
|
| 2860 |
;; Expand in-line code to clear the instruction cache between operand[0] and |
| 2861 |
;; operand[1]. |
| 2862 |
(define_expand "clear_cache" |
| 2863 |
[(match_operand 0 "pmode_register_operand") |
| 2864 |
(match_operand 1 "pmode_register_operand")] |
| 2865 |
"" |
| 2866 |
{ |
| 2867 |
#ifdef ICACHE_FLUSH_FUNC |
| 2868 |
emit_library_call (gen_rtx_SYMBOL_REF (Pmode, ICACHE_FLUSH_FUNC), |
| 2869 |
LCT_NORMAL, VOIDmode, operands[0], Pmode, |
| 2870 |
operands[1], Pmode, const0_rtx, Pmode); |
| 2871 |
#else |
| 2872 |
if (TARGET_ZIFENCEI) |
| 2873 |
emit_insn (gen_fence_i ()); |
| 2874 |
#endif |
| 2875 |
DONE; |
| 2876 |
}) |
| 2877 |
|
| 2878 |
(define_insn "fence" |
| 2879 |
[(unspec_volatile [(const_int 0)] UNSPECV_FENCE)] |
| 2880 |
"" |
| 2881 |
"%|fence%-" |
| 2882 |
[(set_attr "type" "atomic")]) |
| 2883 |
|
| 2884 |
(define_insn "fence_i" |
| 2885 |
[(unspec_volatile [(const_int 0)] UNSPECV_FENCE_I)] |
| 2886 |
"TARGET_ZIFENCEI" |
| 2887 |
"fence.i" |
| 2888 |
[(set_attr "type" "atomic")]) |
| 2889 |
|
| 2890 |
(define_insn "riscv_pause" |
| 2891 |
[(unspec_volatile [(const_int 0)] UNSPECV_PAUSE)] |
| 2892 |
"" |
| 2893 |
"* return TARGET_ZIHINTPAUSE ? \"pause\" : \".insn\t0x0100000f\";" |
| 2894 |
[(set_attr "type" "atomic")]) |
| 2895 |
|
| 2896 |
;; |
| 2897 |
;; .................... |
| 2898 |
;; |
| 2899 |
;; SHIFTS |
| 2900 |
;; |
| 2901 |
;; .................... |
| 2902 |
|
| 2903 |
;; Use a QImode shift count, to avoid generating sign or zero extend |
| 2904 |
;; instructions for shift counts, and to avoid dropping subregs. |
| 2905 |
;; expand_shift_1 can do this automatically when SHIFT_COUNT_TRUNCATED is |
| 2906 |
;; defined, but use of that is discouraged. |
| 2907 |
|
| 2908 |
(define_insn "*<optab>si3" |
| 2909 |
[(set (match_operand:SI 0 "register_operand" "= r") |
| 2910 |
(any_shift:SI |
| 2911 |
(match_operand:SI 1 "register_operand" " r") |
| 2912 |
(match_operand:QI 2 "arith_operand" " rI")))] |
| 2913 |
"" |
| 2914 |
{ |
| 2915 |
if (GET_CODE (operands[2]) == CONST_INT) |
| 2916 |
operands[2] = GEN_INT (INTVAL (operands[2]) |
| 2917 |
& (GET_MODE_BITSIZE (SImode) - 1)); |
| 2918 |
|
| 2919 |
return "<insn>%i2%~\t%0,%1,%2"; |
| 2920 |
} |
| 2921 |
[(set_attr "type" "shift") |
| 2922 |
(set_attr "mode" "SI")]) |
| 2923 |
|
| 2924 |
(define_expand "<optab>si3" |
| 2925 |
[(set (match_operand:SI 0 "register_operand" "= r") |
| 2926 |
(any_shift:SI (match_operand:SI 1 "register_operand" " r") |
| 2927 |
(match_operand:QI 2 "arith_operand" " rI")))] |
| 2928 |
"" |
| 2929 |
{ |
| 2930 |
if (TARGET_64BIT) |
| 2931 |
{ |
| 2932 |
rtx t = gen_reg_rtx (DImode); |
| 2933 |
emit_insn (gen_<optab>si3_extend (t, operands[1], operands[2])); |
| 2934 |
t = gen_lowpart (SImode, t); |
| 2935 |
SUBREG_PROMOTED_VAR_P (t) = 1; |
| 2936 |
SUBREG_PROMOTED_SET (t, SRP_SIGNED); |
| 2937 |
emit_move_insn (operands[0], t); |
| 2938 |
DONE; |
| 2939 |
} |
| 2940 |
}) |
| 2941 |
|
| 2942 |
(define_insn "<optab>di3" |
| 2943 |
[(set (match_operand:DI 0 "register_operand" "= r") |
| 2944 |
(any_shift:DI |
| 2945 |
(match_operand:DI 1 "register_operand" " r") |
| 2946 |
(match_operand:QI 2 "arith_operand" " rI")))] |
| 2947 |
"TARGET_64BIT" |
| 2948 |
{ |
| 2949 |
if (GET_CODE (operands[2]) == CONST_INT) |
| 2950 |
operands[2] = GEN_INT (INTVAL (operands[2]) |
| 2951 |
& (GET_MODE_BITSIZE (DImode) - 1)); |
| 2952 |
|
| 2953 |
return "<insn>%i2\t%0,%1,%2"; |
| 2954 |
} |
| 2955 |
[(set_attr "type" "shift") |
| 2956 |
(set_attr "mode" "DI")]) |
| 2957 |
|
| 2958 |
(define_insn "*<optab><GPR:mode>3_mask_1" |
| 2959 |
[(set (match_operand:GPR 0 "register_operand" "= r") |
| 2960 |
(any_shift:GPR |
| 2961 |
(match_operand:GPR 1 "register_operand" " r") |
| 2962 |
(match_operator 4 "subreg_lowpart_operator" |
| 2963 |
[(and:GPR2 |
| 2964 |
(match_operand:GPR2 2 "register_operand" "r") |
| 2965 |
(match_operand 3 "<GPR:shiftm1>"))])))] |
| 2966 |
"" |
| 2967 |
"<insn>\t%0,%1,%2" |
| 2968 |
[(set_attr "type" "shift") |
| 2969 |
(set_attr "mode" "<GPR:MODE>")]) |
| 2970 |
|
| 2971 |
(define_insn "<optab>si3_extend" |
| 2972 |
[(set (match_operand:DI 0 "register_operand" "= r") |
| 2973 |
(sign_extend:DI |
| 2974 |
(any_shift:SI (match_operand:SI 1 "register_operand" " r") |
| 2975 |
(match_operand:QI 2 "arith_operand" " rI"))))] |
| 2976 |
"TARGET_64BIT" |
| 2977 |
{ |
| 2978 |
if (GET_CODE (operands[2]) == CONST_INT) |
| 2979 |
operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f); |
| 2980 |
|
| 2981 |
return "<insn>%i2w\t%0,%1,%2"; |
| 2982 |
} |
| 2983 |
[(set_attr "type" "shift") |
| 2984 |
(set_attr "mode" "SI")]) |
| 2985 |
|
| 2986 |
(define_insn "*<optab>si3_extend_mask" |
| 2987 |
[(set (match_operand:DI 0 "register_operand" "= r") |
| 2988 |
(sign_extend:DI |
| 2989 |
(any_shift:SI |
| 2990 |
(match_operand:SI 1 "register_operand" " r") |
| 2991 |
(match_operator 4 "subreg_lowpart_operator" |
| 2992 |
[(and:GPR |
| 2993 |
(match_operand:GPR 2 "register_operand" " r") |
| 2994 |
(match_operand 3 "const_si_mask_operand"))]))))] |
| 2995 |
"TARGET_64BIT" |
| 2996 |
"<insn>w\t%0,%1,%2" |
| 2997 |
[(set_attr "type" "shift") |
| 2998 |
(set_attr "mode" "SI")]) |
| 2999 |
|
| 3000 |
;; We can reassociate the shift and bitwise operator which may allow us to |
| 3001 |
;; reduce the immediate operand of the bitwise operator into a range that |
| 3002 |
;; fits in a simm12. |
| 3003 |
;; |
| 3004 |
;; We need to make sure that shifting does not lose any bits, particularly |
| 3005 |
;; for IOR/XOR. It probably doesn't matter for AND. |
| 3006 |
;; |
| 3007 |
;; We also don't want to do this if the immediate already fits in a simm12 |
| 3008 |
;; field, or it is a single bit operand and zbs is available. |
| 3009 |
(define_insn_and_split "<optab>_shift_reverse<X:mode>" |
| 3010 |
[(set (match_operand:X 0 "register_operand" "=r") |
| 3011 |
(any_bitwise:X (ashift:X (match_operand:X 1 "register_operand" "r") |
| 3012 |
(match_operand 2 "immediate_operand" "n")) |
| 3013 |
(match_operand 3 "immediate_operand" "n")))] |
| 3014 |
"(!SMALL_OPERAND (INTVAL (operands[3])) |
| 3015 |
&& SMALL_OPERAND (INTVAL (operands[3]) >> INTVAL (operands[2])) |
| 3016 |
&& (!TARGET_ZBS || popcount_hwi (INTVAL (operands[3])) > 1) |
| 3017 |
&& (INTVAL (operands[3]) & ((1ULL << INTVAL (operands[2])) - 1)) == 0)" |
| 3018 |
"#" |
| 3019 |
"&& 1" |
| 3020 |
[(set (match_dup 0) (any_bitwise:X (match_dup 1) (match_dup 3))) |
| 3021 |
(set (match_dup 0) (ashift:X (match_dup 0) (match_dup 2)))] |
| 3022 |
{ |
| 3023 |
operands[3] = GEN_INT (INTVAL (operands[3]) >> INTVAL (operands[2])); |
| 3024 |
} |
| 3025 |
[(set_attr "type" "shift") |
| 3026 |
(set_attr "mode" "<X:MODE>")]) |
| 3027 |
|
| 3028 |
;; Non-canonical, but can be formed by ree when combine is not successful at |
| 3029 |
;; producing one of the two canonical patterns below. |
| 3030 |
(define_insn "*lshrsi3_zero_extend_1" |
| 3031 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 3032 |
(zero_extend:DI |
| 3033 |
(lshiftrt:SI (match_operand:SI 1 "register_operand" " r") |
| 3034 |
(match_operand 2 "const_int_operand"))))] |
| 3035 |
"TARGET_64BIT && (INTVAL (operands[2]) & 0x1f) > 0" |
| 3036 |
{ |
| 3037 |
operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f); |
| 3038 |
|
| 3039 |
return "srliw\t%0,%1,%2"; |
| 3040 |
} |
| 3041 |
[(set_attr "type" "shift") |
| 3042 |
(set_attr "mode" "SI")]) |
| 3043 |
|
| 3044 |
;; Canonical form for a sign/zero-extend of a logical right shift. |
| 3045 |
;; Special case: extract MSB bits of lower 32-bit word |
| 3046 |
(define_insn "*lshrsi3_extend_2" |
| 3047 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 3048 |
(any_extract:DI (match_operand:DI 1 "register_operand" " r") |
| 3049 |
(match_operand 2 "const_int_operand") |
| 3050 |
(match_operand 3 "const_int_operand")))] |
| 3051 |
"(TARGET_64BIT && (INTVAL (operands[3]) > 0) |
| 3052 |
&& (INTVAL (operands[2]) + INTVAL (operands[3]) == 32))" |
| 3053 |
{ |
| 3054 |
return "<extract_sidi_shift>\t%0,%1,%3"; |
| 3055 |
} |
| 3056 |
[(set_attr "type" "shift") |
| 3057 |
(set_attr "mode" "SI")]) |
| 3058 |
|
| 3059 |
;; Canonical form for a zero-extend of a logical right shift when the |
| 3060 |
;; shift count is 31. |
| 3061 |
(define_insn "*lshrsi3_zero_extend_3" |
| 3062 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 3063 |
(lt:DI (match_operand:SI 1 "register_operand" " r") |
| 3064 |
(const_int 0)))] |
| 3065 |
"TARGET_64BIT" |
| 3066 |
{ |
| 3067 |
return "srliw\t%0,%1,31"; |
| 3068 |
} |
| 3069 |
[(set_attr "type" "shift") |
| 3070 |
(set_attr "mode" "SI")]) |
| 3071 |
|
| 3072 |
;; Canonical form for a extend of a logical shift right (sign/zero extraction). |
| 3073 |
;; Special cases, that are ignored (handled elsewhere): |
| 3074 |
;; * Single-bit extraction (Zbs/XTheadBs) |
| 3075 |
;; * Single-bit extraction (Zicondops/XVentanaCondops) |
| 3076 |
;; * Single-bit extraction (SFB) |
| 3077 |
;; * Extraction instruction th.ext(u) (XTheadBb) |
| 3078 |
;; * lshrsi3_extend_2 (see above) |
| 3079 |
(define_insn_and_split "*<any_extract:optab><GPR:mode>3" |
| 3080 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 3081 |
(any_extract:GPR |
| 3082 |
(match_operand:GPR 1 "register_operand" " r") |
| 3083 |
(match_operand 2 "const_int_operand") |
| 3084 |
(match_operand 3 "const_int_operand"))) |
| 3085 |
(clobber (match_scratch:GPR 4 "=&r"))] |
| 3086 |
"!((TARGET_ZBS || TARGET_XTHEADBS || TARGET_ZICOND |
| 3087 |
|| TARGET_XVENTANACONDOPS || TARGET_SFB_ALU) |
| 3088 |
&& (INTVAL (operands[2]) == 1)) |
| 3089 |
&& !TARGET_XTHEADBB |
| 3090 |
&& !(TARGET_64BIT |
| 3091 |
&& (INTVAL (operands[3]) > 0) |
| 3092 |
&& (INTVAL (operands[2]) + INTVAL (operands[3]) == 32))" |
| 3093 |
"#" |
| 3094 |
"&& reload_completed" |
| 3095 |
[(set (match_dup 4) |
| 3096 |
(ashift:GPR (match_dup 1) (match_dup 2))) |
| 3097 |
(set (match_dup 0) |
| 3098 |
(<extract_shift>:GPR (match_dup 4) (match_dup 3)))] |
| 3099 |
{ |
| 3100 |
int regbits = GET_MODE_BITSIZE (GET_MODE (operands[0])).to_constant (); |
| 3101 |
int sizebits = INTVAL (operands[2]); |
| 3102 |
int startbits = INTVAL (operands[3]); |
| 3103 |
int lshamt = regbits - sizebits - startbits; |
| 3104 |
int rshamt = lshamt + startbits; |
| 3105 |
operands[2] = GEN_INT (lshamt); |
| 3106 |
operands[3] = GEN_INT (rshamt); |
| 3107 |
} |
| 3108 |
[(set_attr "type" "shift") |
| 3109 |
(set_attr "mode" "<GPR:MODE>")]) |
| 3110 |
|
| 3111 |
;; Handle AND with 2^N-1 for N from 12 to XLEN. This can be split into |
| 3112 |
;; two logical shifts. Otherwise it requires 3 instructions: lui, |
| 3113 |
;; xor/addi/srli, and. |
| 3114 |
|
| 3115 |
;; Generating a temporary for the shift output gives better combiner results; |
| 3116 |
;; and also fixes a problem where op0 could be a paradoxical reg and shifting |
| 3117 |
;; by amounts larger than the size of the SUBREG_REG doesn't work. |
| 3118 |
(define_split |
| 3119 |
[(set (match_operand:GPR 0 "register_operand") |
| 3120 |
(and:GPR (match_operand:GPR 1 "register_operand") |
| 3121 |
(match_operand:GPR 2 "p2m1_shift_operand"))) |
| 3122 |
(clobber (match_operand:GPR 3 "register_operand"))] |
| 3123 |
"" |
| 3124 |
[(set (match_dup 3) |
| 3125 |
(ashift:GPR (match_dup 1) (match_dup 2))) |
| 3126 |
(set (match_dup 0) |
| 3127 |
(lshiftrt:GPR (match_dup 3) (match_dup 2)))] |
| 3128 |
{ |
| 3129 |
/* Op2 is a VOIDmode constant, so get the mode size from op1. */ |
| 3130 |
operands[2] = GEN_INT (GET_MODE_BITSIZE (GET_MODE (operands[1])).to_constant () |
| 3131 |
- exact_log2 (INTVAL (operands[2]) + 1)); |
| 3132 |
}) |
| 3133 |
|
| 3134 |
;; Handle AND with 0xF...F0...0 where there are 32 to 63 zeros. This can be |
| 3135 |
;; split into two shifts. Otherwise it requires 3 instructions: li, sll, and. |
| 3136 |
(define_split |
| 3137 |
[(set (match_operand:DI 0 "register_operand") |
| 3138 |
(and:DI (match_operand:DI 1 "register_operand") |
| 3139 |
(match_operand:DI 2 "high_mask_shift_operand"))) |
| 3140 |
(clobber (match_operand:DI 3 "register_operand"))] |
| 3141 |
"TARGET_64BIT" |
| 3142 |
[(set (match_dup 3) |
| 3143 |
(lshiftrt:DI (match_dup 1) (match_dup 2))) |
| 3144 |
(set (match_dup 0) |
| 3145 |
(ashift:DI (match_dup 3) (match_dup 2)))] |
| 3146 |
{ |
| 3147 |
operands[2] = GEN_INT (ctz_hwi (INTVAL (operands[2]))); |
| 3148 |
}) |
| 3149 |
|
| 3150 |
;; Handle SImode to DImode zero-extend combined with a left shift. This can |
| 3151 |
;; occur when unsigned int is used for array indexing. Split this into two |
| 3152 |
;; shifts. Otherwise we can get 3 shifts. |
| 3153 |
|
| 3154 |
(define_insn_and_split "zero_extendsidi2_shifted" |
| 3155 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 3156 |
(and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r") |
| 3157 |
(match_operand:QI 2 "immediate_operand" "I")) |
| 3158 |
(match_operand 3 "immediate_operand" ""))) |
| 3159 |
(clobber (match_scratch:DI 4 "=&r"))] |
| 3160 |
"TARGET_64BIT && !TARGET_ZBA |
| 3161 |
&& ((INTVAL (operands[3]) >> INTVAL (operands[2])) == 0xffffffff)" |
| 3162 |
"#" |
| 3163 |
"&& reload_completed" |
| 3164 |
[(set (match_dup 4) |
| 3165 |
(ashift:DI (match_dup 1) (const_int 32))) |
| 3166 |
(set (match_dup 0) |
| 3167 |
(lshiftrt:DI (match_dup 4) (match_dup 5)))] |
| 3168 |
"operands[5] = GEN_INT (32 - (INTVAL (operands [2])));" |
| 3169 |
[(set_attr "type" "shift") |
| 3170 |
(set_attr "mode" "DI")]) |
| 3171 |
|
| 3172 |
;; |
| 3173 |
;; .................... |
| 3174 |
;; |
| 3175 |
;; CONDITIONAL BRANCHES |
| 3176 |
;; |
| 3177 |
;; .................... |
| 3178 |
|
| 3179 |
;; Conditional branches |
| 3180 |
|
| 3181 |
(define_insn_and_split "*branch<ANYI:mode>_shiftedarith_equals_zero" |
| 3182 |
[(set (pc) |
| 3183 |
(if_then_else (match_operator 1 "equality_operator" |
| 3184 |
[(and:ANYI (match_operand:ANYI 2 "register_operand" "r") |
| 3185 |
(match_operand 3 "shifted_const_arith_operand" "i")) |
| 3186 |
(const_int 0)]) |
| 3187 |
(label_ref (match_operand 0 "" "")) |
| 3188 |
(pc))) |
| 3189 |
(clobber (match_scratch:X 4 "=&r"))] |
| 3190 |
"!SMALL_OPERAND (INTVAL (operands[3]))" |
| 3191 |
"#" |
| 3192 |
"&& reload_completed" |
| 3193 |
[(set (match_dup 4) (lshiftrt:X (subreg:X (match_dup 2) 0) (match_dup 6))) |
| 3194 |
(set (match_dup 4) (and:X (match_dup 4) (match_dup 7))) |
| 3195 |
(set (pc) (if_then_else (match_op_dup 1 [(match_dup 4) (const_int 0)]) |
| 3196 |
(label_ref (match_dup 0)) (pc)))] |
| 3197 |
{ |
| 3198 |
HOST_WIDE_INT mask = INTVAL (operands[3]); |
| 3199 |
int trailing = ctz_hwi (mask); |
| 3200 |
|
| 3201 |
operands[6] = GEN_INT (trailing); |
| 3202 |
operands[7] = GEN_INT (mask >> trailing); |
| 3203 |
} |
| 3204 |
[(set_attr "type" "branch")]) |
| 3205 |
|
| 3206 |
(define_insn_and_split "*branch<ANYI:mode>_shiftedarith_<optab>_shifted" |
| 3207 |
[(set (pc) |
| 3208 |
(if_then_else (any_eq |
| 3209 |
(and:ANYI (match_operand:ANYI 1 "register_operand" "r") |
| 3210 |
(match_operand 2 "shifted_const_arith_operand" "i")) |
| 3211 |
(match_operand 3 "shifted_const_arith_operand" "i")) |
| 3212 |
(label_ref (match_operand 0 "" "")) |
| 3213 |
(pc))) |
| 3214 |
(clobber (match_scratch:X 4 "=&r")) |
| 3215 |
(clobber (match_scratch:X 5 "=&r"))] |
| 3216 |
"!SMALL_OPERAND (INTVAL (operands[2])) |
| 3217 |
&& !SMALL_OPERAND (INTVAL (operands[3])) |
| 3218 |
&& SMALL_AFTER_COMMON_TRAILING_SHIFT (INTVAL (operands[2]), |
| 3219 |
INTVAL (operands[3]))" |
| 3220 |
"#" |
| 3221 |
"&& reload_completed" |
| 3222 |
[(set (match_dup 4) (ashiftrt:X (match_dup 1) (match_dup 7))) |
| 3223 |
(set (match_dup 4) (match_dup 10)) |
| 3224 |
(set (match_dup 5) (match_dup 9)) |
| 3225 |
(set (pc) (if_then_else (any_eq (match_dup 4) (match_dup 5)) |
| 3226 |
(label_ref (match_dup 0)) (pc)))] |
| 3227 |
{ |
| 3228 |
HOST_WIDE_INT mask1 = INTVAL (operands[2]); |
| 3229 |
HOST_WIDE_INT mask2 = INTVAL (operands[3]); |
| 3230 |
int trailing_shift = COMMON_TRAILING_ZEROS (mask1, mask2); |
| 3231 |
|
| 3232 |
operands[7] = GEN_INT (trailing_shift); |
| 3233 |
operands[8] = GEN_INT (mask1 >> trailing_shift); |
| 3234 |
operands[9] = GEN_INT (mask2 >> trailing_shift); |
| 3235 |
|
| 3236 |
/* This splits after reload, so there's little chance to clean things |
| 3237 |
up. Rather than emit a ton of RTL here, we can just make a new |
| 3238 |
operand for that RHS and use it. For the case where the AND would |
| 3239 |
have been redundant, we can make it a NOP move, which does get |
| 3240 |
cleaned up. */ |
| 3241 |
if (operands[8] == CONSTM1_RTX (word_mode)) |
| 3242 |
operands[10] = operands[4]; |
| 3243 |
else |
| 3244 |
operands[10] = gen_rtx_AND (word_mode, operands[4], operands[8]); |
| 3245 |
} |
| 3246 |
[(set_attr "type" "branch")]) |
| 3247 |
|
| 3248 |
(define_insn_and_split "*branch<ANYI:mode>_shiftedmask_equals_zero" |
| 3249 |
[(set (pc) |
| 3250 |
(if_then_else (match_operator 1 "equality_operator" |
| 3251 |
[(and:ANYI (match_operand:ANYI 2 "register_operand" "r") |
| 3252 |
(match_operand 3 "consecutive_bits_operand" "i")) |
| 3253 |
(const_int 0)]) |
| 3254 |
(label_ref (match_operand 0 "" "")) |
| 3255 |
(pc))) |
| 3256 |
(clobber (match_scratch:X 4 "=&r"))] |
| 3257 |
"(INTVAL (operands[3]) >= 0 || !partial_subreg_p (operands[2])) |
| 3258 |
&& popcount_hwi (INTVAL (operands[3])) > 1 |
| 3259 |
&& !SMALL_OPERAND (INTVAL (operands[3]))" |
| 3260 |
"#" |
| 3261 |
"&& reload_completed" |
| 3262 |
[(set (match_dup 4) (ashift:X (subreg:X (match_dup 2) 0) (match_dup 6))) |
| 3263 |
(set (match_dup 4) (lshiftrt:X (match_dup 4) (match_dup 7))) |
| 3264 |
(set (pc) (if_then_else (match_op_dup 1 [(match_dup 4) (const_int 0)]) |
| 3265 |
(label_ref (match_dup 0)) (pc)))] |
| 3266 |
{ |
| 3267 |
unsigned HOST_WIDE_INT mask = INTVAL (operands[3]); |
| 3268 |
int leading = clz_hwi (mask); |
| 3269 |
int trailing = ctz_hwi (mask); |
| 3270 |
|
| 3271 |
operands[6] = GEN_INT (leading); |
| 3272 |
operands[7] = GEN_INT (leading + trailing); |
| 3273 |
} |
| 3274 |
[(set_attr "type" "branch")]) |
| 3275 |
|
| 3276 |
(define_insn "*branch<mode>" |
| 3277 |
[(set (pc) |
| 3278 |
(if_then_else |
| 3279 |
(match_operator 1 "ordered_comparison_operator" |
| 3280 |
[(match_operand:X 2 "register_operand" "r") |
| 3281 |
(match_operand:X 3 "reg_or_0_operand" "rJ")]) |
| 3282 |
(label_ref (match_operand 0 "" "")) |
| 3283 |
(pc)))] |
| 3284 |
"!TARGET_XCVBI" |
| 3285 |
{ |
| 3286 |
if (get_attr_length (insn) == 12) |
| 3287 |
return "b%r1\t%2,%z3,1f; jump\t%l0,ra; 1:"; |
| 3288 |
|
| 3289 |
return "b%C1\t%2,%z3,%l0"; |
| 3290 |
} |
| 3291 |
[(set_attr "type" "branch") |
| 3292 |
(set_attr "mode" "none")]) |
| 3293 |
|
| 3294 |
;; Conditional move and add patterns. |
| 3295 |
|
| 3296 |
(define_expand "mov<mode>cc" |
| 3297 |
[(set (match_operand:GPR 0 "register_operand") |
| 3298 |
(if_then_else:GPR (match_operand 1 "comparison_operator") |
| 3299 |
(match_operand:GPR 2 "movcc_operand") |
| 3300 |
(match_operand:GPR 3 "movcc_operand")))] |
| 3301 |
"TARGET_SFB_ALU || TARGET_XTHEADCONDMOV || TARGET_ZICOND_LIKE |
| 3302 |
|| TARGET_MOVCC" |
| 3303 |
{ |
| 3304 |
if (riscv_expand_conditional_move (operands[0], operands[1], |
| 3305 |
operands[2], operands[3])) |
| 3306 |
DONE; |
| 3307 |
else |
| 3308 |
FAIL; |
| 3309 |
}) |
| 3310 |
|
| 3311 |
(define_expand "add<mode>cc" |
| 3312 |
[(match_operand:GPR 0 "register_operand") |
| 3313 |
(match_operand 1 "comparison_operator") |
| 3314 |
(match_operand:GPR 2 "arith_operand") |
| 3315 |
(match_operand:GPR 3 "arith_operand")] |
| 3316 |
"TARGET_MOVCC" |
| 3317 |
{ |
| 3318 |
rtx cmp = operands[1]; |
| 3319 |
rtx cmp0 = XEXP (cmp, 0); |
| 3320 |
rtx cmp1 = XEXP (cmp, 1); |
| 3321 |
machine_mode mode0 = GET_MODE (cmp0); |
| 3322 |
|
| 3323 |
/* We only handle word mode integer compares for now. */ |
| 3324 |
if (INTEGRAL_MODE_P (mode0) && mode0 != word_mode) |
| 3325 |
FAIL; |
| 3326 |
|
| 3327 |
enum rtx_code code = GET_CODE (cmp); |
| 3328 |
rtx reg0 = gen_reg_rtx (<MODE>mode); |
| 3329 |
rtx reg1 = gen_reg_rtx (<MODE>mode); |
| 3330 |
rtx reg2 = gen_reg_rtx (<MODE>mode); |
| 3331 |
bool invert = false; |
| 3332 |
|
| 3333 |
if (INTEGRAL_MODE_P (mode0)) |
| 3334 |
riscv_expand_int_scc (reg0, code, cmp0, cmp1, &invert); |
| 3335 |
else if (FLOAT_MODE_P (mode0) && fp_scc_comparison (cmp, GET_MODE (cmp))) |
| 3336 |
riscv_expand_float_scc (reg0, code, cmp0, cmp1, &invert); |
| 3337 |
else |
| 3338 |
FAIL; |
| 3339 |
|
| 3340 |
if (invert) |
| 3341 |
riscv_emit_binary (PLUS, reg1, reg0, constm1_rtx); |
| 3342 |
else |
| 3343 |
riscv_emit_unary (NEG, reg1, reg0); |
| 3344 |
riscv_emit_binary (AND, reg2, reg1, operands[3]); |
| 3345 |
riscv_emit_binary (PLUS, operands[0], reg2, operands[2]); |
| 3346 |
|
| 3347 |
DONE; |
| 3348 |
}) |
| 3349 |
|
| 3350 |
;; Used to implement built-in functions. |
| 3351 |
(define_expand "condjump" |
| 3352 |
[(set (pc) |
| 3353 |
(if_then_else (match_operand 0) |
| 3354 |
(label_ref (match_operand 1)) |
| 3355 |
(pc)))]) |
| 3356 |
|
| 3357 |
(define_expand "@cbranch<mode>4" |
| 3358 |
[(set (pc) |
| 3359 |
(if_then_else (match_operator 0 "comparison_operator" |
| 3360 |
[(match_operand:BR 1 "register_operand") |
| 3361 |
(match_operand:BR 2 "nonmemory_operand")]) |
| 3362 |
(label_ref (match_operand 3 "")) |
| 3363 |
(pc)))] |
| 3364 |
"" |
| 3365 |
{ |
| 3366 |
riscv_expand_conditional_branch (operands[3], GET_CODE (operands[0]), |
| 3367 |
operands[1], operands[2]); |
| 3368 |
DONE; |
| 3369 |
}) |
| 3370 |
|
| 3371 |
(define_expand "@cbranch<ANYF:mode>4" |
| 3372 |
[(parallel [(set (pc) |
| 3373 |
(if_then_else (match_operator 0 "fp_branch_comparison" |
| 3374 |
[(match_operand:ANYF 1 "register_operand") |
| 3375 |
(match_operand:ANYF 2 "register_operand")]) |
| 3376 |
(label_ref (match_operand 3 "")) |
| 3377 |
(pc))) |
| 3378 |
(clobber (match_operand 4 ""))])] |
| 3379 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 3380 |
{ |
| 3381 |
if (!signed_order_operator (operands[0], GET_MODE (operands[0]))) |
| 3382 |
{ |
| 3383 |
riscv_expand_conditional_branch (operands[3], GET_CODE (operands[0]), |
| 3384 |
operands[1], operands[2]); |
| 3385 |
DONE; |
| 3386 |
} |
| 3387 |
operands[4] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode); |
| 3388 |
}) |
| 3389 |
|
| 3390 |
(define_insn_and_split "*cbranch<ANYF:mode>4" |
| 3391 |
[(set (pc) |
| 3392 |
(if_then_else (match_operator 1 "fp_native_comparison" |
| 3393 |
[(match_operand:ANYF 2 "register_operand" "f") |
| 3394 |
(match_operand:ANYF 3 "register_operand" "f")]) |
| 3395 |
(label_ref (match_operand 0 "")) |
| 3396 |
(pc))) |
| 3397 |
(clobber (match_operand:X 4 "register_operand" "=r"))] |
| 3398 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 3399 |
"#" |
| 3400 |
"&& reload_completed" |
| 3401 |
[(set (match_dup 4) |
| 3402 |
(match_op_dup:X 1 [(match_dup 2) (match_dup 3)])) |
| 3403 |
(set (pc) |
| 3404 |
(if_then_else (ne:X (match_dup 4) (const_int 0)) |
| 3405 |
(label_ref (match_operand 0)) |
| 3406 |
(pc)))] |
| 3407 |
"" |
| 3408 |
[(set_attr "type" "branch") |
| 3409 |
(set (attr "length") |
| 3410 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 3411 |
(const_int 4084)) |
| 3412 |
(le (minus (pc) (match_dup 0)) |
| 3413 |
(const_int 4096))) |
| 3414 |
(const_int 8) |
| 3415 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 3416 |
(const_int 1048564)) |
| 3417 |
(le (minus (pc) (match_dup 0)) |
| 3418 |
(const_int 1048576))) |
| 3419 |
(const_int 12) |
| 3420 |
(const_int 16))))]) |
| 3421 |
|
| 3422 |
(define_insn_and_split "*cbranch<ANYF:mode>4" |
| 3423 |
[(set (pc) |
| 3424 |
(if_then_else (match_operator 1 "ne_operator" |
| 3425 |
[(match_operand:ANYF 2 "register_operand" "f") |
| 3426 |
(match_operand:ANYF 3 "register_operand" "f")]) |
| 3427 |
(label_ref (match_operand 0 "")) |
| 3428 |
(pc))) |
| 3429 |
(clobber (match_operand:X 4 "register_operand" "=r"))] |
| 3430 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 3431 |
"#" |
| 3432 |
"&& reload_completed" |
| 3433 |
[(set (match_dup 4) |
| 3434 |
(eq:X (match_dup 2) (match_dup 3))) |
| 3435 |
(set (pc) |
| 3436 |
(if_then_else (eq:X (match_dup 4) (const_int 0)) |
| 3437 |
(label_ref (match_operand 0)) |
| 3438 |
(pc)))] |
| 3439 |
"" |
| 3440 |
[(set_attr "type" "branch") |
| 3441 |
(set (attr "length") |
| 3442 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 3443 |
(const_int 4084)) |
| 3444 |
(le (minus (pc) (match_dup 0)) |
| 3445 |
(const_int 4096))) |
| 3446 |
(const_int 8) |
| 3447 |
(if_then_else (and (le (minus (match_dup 0) (pc)) |
| 3448 |
(const_int 1048564)) |
| 3449 |
(le (minus (pc) (match_dup 0)) |
| 3450 |
(const_int 1048576))) |
| 3451 |
(const_int 12) |
| 3452 |
(const_int 16))))]) |
| 3453 |
|
| 3454 |
(define_insn_and_split "*branch_on_bit<X:mode>" |
| 3455 |
[(set (pc) |
| 3456 |
(if_then_else |
| 3457 |
(match_operator 0 "equality_operator" |
| 3458 |
[(zero_extract:X (match_operand:X 2 "register_operand" "r") |
| 3459 |
(const_int 1) |
| 3460 |
(match_operand 3 "branch_on_bit_operand")) |
| 3461 |
(const_int 0)]) |
| 3462 |
(label_ref (match_operand 1)) |
| 3463 |
(pc))) |
| 3464 |
(clobber (match_scratch:X 4 "=&r"))] |
| 3465 |
"" |
| 3466 |
"#" |
| 3467 |
"reload_completed" |
| 3468 |
[(set (match_dup 4) |
| 3469 |
(ashift:X (match_dup 2) (match_dup 3))) |
| 3470 |
(set (pc) |
| 3471 |
(if_then_else |
| 3472 |
(match_op_dup 0 [(match_dup 4) (const_int 0)]) |
| 3473 |
(label_ref (match_operand 1)) |
| 3474 |
(pc)))] |
| 3475 |
{ |
| 3476 |
int shift = GET_MODE_BITSIZE (<MODE>mode) - 1 - INTVAL (operands[3]); |
| 3477 |
operands[3] = GEN_INT (shift); |
| 3478 |
|
| 3479 |
if (GET_CODE (operands[0]) == EQ) |
| 3480 |
operands[0] = gen_rtx_GE (<MODE>mode, operands[4], const0_rtx); |
| 3481 |
else |
| 3482 |
operands[0] = gen_rtx_LT (<MODE>mode, operands[4], const0_rtx); |
| 3483 |
} |
| 3484 |
[(set_attr "type" "branch")]) |
| 3485 |
|
| 3486 |
(define_insn_and_split "*branch_on_bit_range<X:mode>" |
| 3487 |
[(set (pc) |
| 3488 |
(if_then_else |
| 3489 |
(match_operator 0 "equality_operator" |
| 3490 |
[(zero_extract:X (match_operand:X 2 "register_operand" "r") |
| 3491 |
(match_operand 3 "branch_on_bit_operand") |
| 3492 |
(const_int 0)) |
| 3493 |
(const_int 0)]) |
| 3494 |
(label_ref (match_operand 1)) |
| 3495 |
(pc))) |
| 3496 |
(clobber (match_scratch:X 4 "=&r"))] |
| 3497 |
"" |
| 3498 |
"#" |
| 3499 |
"reload_completed" |
| 3500 |
[(set (match_dup 4) |
| 3501 |
(ashift:X (match_dup 2) (match_dup 3))) |
| 3502 |
(set (pc) |
| 3503 |
(if_then_else |
| 3504 |
(match_op_dup 0 [(match_dup 4) (const_int 0)]) |
| 3505 |
(label_ref (match_operand 1)) |
| 3506 |
(pc)))] |
| 3507 |
{ |
| 3508 |
operands[3] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - INTVAL (operands[3])); |
| 3509 |
} |
| 3510 |
[(set_attr "type" "branch")]) |
| 3511 |
|
| 3512 |
;; |
| 3513 |
;; .................... |
| 3514 |
;; |
| 3515 |
;; SETTING A REGISTER FROM A COMPARISON |
| 3516 |
;; |
| 3517 |
;; .................... |
| 3518 |
|
| 3519 |
;; Destination is always set in SI mode. |
| 3520 |
|
| 3521 |
(define_expand "cstore<mode>4" |
| 3522 |
[(set (match_operand:SI 0 "register_operand") |
| 3523 |
(match_operator:SI 1 "ordered_comparison_operator" |
| 3524 |
[(match_operand:GPR 2 "register_operand") |
| 3525 |
(match_operand:GPR 3 "nonmemory_operand")]))] |
| 3526 |
"" |
| 3527 |
{ |
| 3528 |
riscv_expand_int_scc (operands[0], GET_CODE (operands[1]), operands[2], |
| 3529 |
operands[3]); |
| 3530 |
DONE; |
| 3531 |
}) |
| 3532 |
|
| 3533 |
(define_expand "cstore<mode>4" |
| 3534 |
[(set (match_operand:SI 0 "register_operand") |
| 3535 |
(match_operator:SI 1 "fp_scc_comparison" |
| 3536 |
[(match_operand:ANYF 2 "register_operand") |
| 3537 |
(match_operand:ANYF 3 "register_operand")]))] |
| 3538 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 3539 |
{ |
| 3540 |
riscv_expand_float_scc (operands[0], GET_CODE (operands[1]), operands[2], |
| 3541 |
operands[3]); |
| 3542 |
DONE; |
| 3543 |
}) |
| 3544 |
|
| 3545 |
(define_insn "*cstore<ANYF:mode><X:mode>4" |
| 3546 |
[(set (match_operand:X 0 "register_operand" "=r") |
| 3547 |
(match_operator:X 1 "fp_native_comparison" |
| 3548 |
[(match_operand:ANYF 2 "register_operand" " f") |
| 3549 |
(match_operand:ANYF 3 "register_operand" " f")]))] |
| 3550 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 3551 |
"f%C1.<fmt>\t%0,%2,%3" |
| 3552 |
[(set_attr "type" "fcmp") |
| 3553 |
(set_attr "mode" "<UNITMODE>")]) |
| 3554 |
|
| 3555 |
(define_expand "f<quiet_pattern>_quiet<ANYF:mode><X:mode>4" |
| 3556 |
[(set (match_operand:X 0 "register_operand") |
| 3557 |
(unspec:X [(match_operand:ANYF 1 "register_operand") |
| 3558 |
(match_operand:ANYF 2 "register_operand")] |
| 3559 |
QUIET_COMPARISON))] |
| 3560 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 3561 |
{ |
| 3562 |
rtx op0 = operands[0]; |
| 3563 |
rtx op1 = operands[1]; |
| 3564 |
rtx op2 = operands[2]; |
| 3565 |
|
| 3566 |
if (TARGET_ZFA) |
| 3567 |
emit_insn (gen_f<quiet_pattern>_quiet<ANYF:mode><X:mode>4_zfa(op0, op1, op2)); |
| 3568 |
else |
| 3569 |
{ |
| 3570 |
rtx tmp = gen_reg_rtx (SImode); |
| 3571 |
rtx cmp = gen_rtx_<QUIET_PATTERN> (<X:MODE>mode, op1, op2); |
| 3572 |
rtx frflags = gen_rtx_UNSPEC_VOLATILE (SImode, gen_rtvec (1, const0_rtx), |
| 3573 |
UNSPECV_FRFLAGS); |
| 3574 |
rtx fsflags = gen_rtx_UNSPEC_VOLATILE (SImode, gen_rtvec (1, tmp), |
| 3575 |
UNSPECV_FSFLAGS); |
| 3576 |
|
| 3577 |
emit_insn (gen_rtx_SET (tmp, frflags)); |
| 3578 |
emit_insn (gen_rtx_SET (op0, cmp)); |
| 3579 |
emit_insn (fsflags); |
| 3580 |
} |
| 3581 |
|
| 3582 |
if (HONOR_SNANS (<ANYF:MODE>mode)) |
| 3583 |
emit_insn (gen_rtx_UNSPEC_VOLATILE (<ANYF:MODE>mode, |
| 3584 |
gen_rtvec (2, op1, op2), |
| 3585 |
UNSPECV_FSNVSNAN)); |
| 3586 |
DONE; |
| 3587 |
}) |
| 3588 |
|
| 3589 |
(define_insn "f<quiet_pattern>_quiet<ANYF:mode><X:mode>4_zfa" |
| 3590 |
[(set (match_operand:X 0 "register_operand" "=r") |
| 3591 |
(unspec:X |
| 3592 |
[(match_operand:ANYF 1 "register_operand" " f") |
| 3593 |
(match_operand:ANYF 2 "register_operand" " f")] |
| 3594 |
QUIET_COMPARISON))] |
| 3595 |
"TARGET_HARD_FLOAT && TARGET_ZFA" |
| 3596 |
"f<quiet_pattern>q.<fmt>\t%0,%1,%2" |
| 3597 |
[(set_attr "type" "fcmp") |
| 3598 |
(set_attr "mode" "<UNITMODE>") |
| 3599 |
(set (attr "length") (const_int 16))]) |
| 3600 |
|
| 3601 |
;; fclass instruction output bitmap |
| 3602 |
;; 0 negative infinity |
| 3603 |
;; 1 negative normal number. |
| 3604 |
;; 2 negative subnormal number. |
| 3605 |
;; 3 -0 |
| 3606 |
;; 4 +0 |
| 3607 |
;; 5 positive subnormal number. |
| 3608 |
;; 6 positive normal number. |
| 3609 |
;; 7 positive infinity |
| 3610 |
;; 8 signaling NaN. |
| 3611 |
;; 9 quiet NaN |
| 3612 |
|
| 3613 |
(define_insn "fclass<ANYF:mode><X:mode>" |
| 3614 |
[(set (match_operand:X 0 "register_operand" "=r") |
| 3615 |
(unspec [(match_operand:ANYF 1 "register_operand" " f")] |
| 3616 |
UNSPEC_FCLASS))] |
| 3617 |
"TARGET_HARD_FLOAT" |
| 3618 |
"fclass.<fmt>\t%0,%1"; |
| 3619 |
[(set_attr "type" "fcmp") |
| 3620 |
(set_attr "mode" "<UNITMODE>")]) |
| 3621 |
|
| 3622 |
;; Implements optab for isfinite, isnormal, isinf |
| 3623 |
|
| 3624 |
(define_int_iterator FCLASS_MASK [126 66 129]) |
| 3625 |
(define_int_attr fclass_optab |
| 3626 |
[(126 "isfinite") |
| 3627 |
(66 "isnormal") |
| 3628 |
(129 "isinf")]) |
| 3629 |
|
| 3630 |
(define_expand "<FCLASS_MASK:fclass_optab><ANYF:mode>2" |
| 3631 |
[(match_operand 0 "register_operand" "=r") |
| 3632 |
(match_operand:ANYF 1 "register_operand" " f") |
| 3633 |
(const_int FCLASS_MASK)] |
| 3634 |
"TARGET_HARD_FLOAT" |
| 3635 |
{ |
| 3636 |
if (GET_MODE (operands[0]) != SImode |
| 3637 |
&& GET_MODE (operands[0]) != word_mode) |
| 3638 |
FAIL; |
| 3639 |
|
| 3640 |
rtx t = gen_reg_rtx (word_mode); |
| 3641 |
rtx t_op0 = gen_reg_rtx (word_mode); |
| 3642 |
|
| 3643 |
if (TARGET_64BIT) |
| 3644 |
emit_insn (gen_fclass<ANYF:mode>di (t, operands[1])); |
| 3645 |
else |
| 3646 |
emit_insn (gen_fclass<ANYF:mode>si (t, operands[1])); |
| 3647 |
|
| 3648 |
riscv_emit_binary (AND, t, t, GEN_INT (<FCLASS_MASK>)); |
| 3649 |
rtx cmp = gen_rtx_NE (word_mode, t, const0_rtx); |
| 3650 |
emit_insn (gen_cstore<mode>4 (t_op0, cmp, t, const0_rtx)); |
| 3651 |
|
| 3652 |
if (TARGET_64BIT) |
| 3653 |
{ |
| 3654 |
t_op0 = gen_lowpart (SImode, t_op0); |
| 3655 |
SUBREG_PROMOTED_VAR_P (t_op0) = 1; |
| 3656 |
SUBREG_PROMOTED_SET (t_op0, SRP_SIGNED); |
| 3657 |
} |
| 3658 |
|
| 3659 |
emit_move_insn (operands[0], t_op0); |
| 3660 |
DONE; |
| 3661 |
}) |
| 3662 |
|
| 3663 |
(define_insn "*seq_zero_<X:mode><GPR:mode>" |
| 3664 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 3665 |
(eq:GPR (match_operand:X 1 "register_operand" " r") |
| 3666 |
(const_int 0)))] |
| 3667 |
"" |
| 3668 |
"seqz\t%0,%1" |
| 3669 |
[(set_attr "type" "slt") |
| 3670 |
(set_attr "mode" "<X:MODE>")]) |
| 3671 |
|
| 3672 |
(define_insn "*sne_zero_<X:mode><GPR:mode>" |
| 3673 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 3674 |
(ne:GPR (match_operand:X 1 "register_operand" " r") |
| 3675 |
(const_int 0)))] |
| 3676 |
"" |
| 3677 |
"snez\t%0,%1" |
| 3678 |
[(set_attr "type" "slt") |
| 3679 |
(set_attr "mode" "<X:MODE>")]) |
| 3680 |
|
| 3681 |
(define_insn "*sgt<u>_<X:mode><GPR:mode>" |
| 3682 |
[(set (match_operand:GPR 0 "register_operand" "= r") |
| 3683 |
(any_gt:GPR (match_operand:X 1 "register_operand" " r") |
| 3684 |
(match_operand:X 2 "reg_or_0_operand" " rJ")))] |
| 3685 |
"" |
| 3686 |
"sgt<u>\t%0,%1,%z2" |
| 3687 |
[(set_attr "type" "slt") |
| 3688 |
(set_attr "mode" "<X:MODE>")]) |
| 3689 |
|
| 3690 |
(define_insn "*sge<u>_<X:mode><GPR:mode>" |
| 3691 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 3692 |
(any_ge:GPR (match_operand:X 1 "register_operand" " r") |
| 3693 |
(const_int 1)))] |
| 3694 |
"" |
| 3695 |
"slti<u>\t%0,zero,%1" |
| 3696 |
[(set_attr "type" "slt") |
| 3697 |
(set_attr "mode" "<X:MODE>")]) |
| 3698 |
|
| 3699 |
(define_insn "@slt<u>_<X:mode><GPR:mode>3" |
| 3700 |
[(set (match_operand:GPR 0 "register_operand" "= r") |
| 3701 |
(any_lt:GPR (match_operand:X 1 "register_operand" " r") |
| 3702 |
(match_operand:X 2 "arith_operand" " rI")))] |
| 3703 |
"" |
| 3704 |
"slt%i2<u>\t%0,%1,%2" |
| 3705 |
[(set_attr "type" "slt") |
| 3706 |
(set_attr "mode" "<X:MODE>")]) |
| 3707 |
|
| 3708 |
(define_insn "*sle<u>_<X:mode><GPR:mode>" |
| 3709 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 3710 |
(any_le:GPR (match_operand:X 1 "register_operand" " r") |
| 3711 |
(match_operand:X 2 "sle_operand" "")))] |
| 3712 |
"" |
| 3713 |
{ |
| 3714 |
operands[2] = GEN_INT (INTVAL (operands[2]) + 1); |
| 3715 |
return "slt%i2<u>\t%0,%1,%2"; |
| 3716 |
} |
| 3717 |
[(set_attr "type" "slt") |
| 3718 |
(set_attr "mode" "<X:MODE>")]) |
| 3719 |
|
| 3720 |
;; |
| 3721 |
;; .................... |
| 3722 |
;; |
| 3723 |
;; UNCONDITIONAL BRANCHES |
| 3724 |
;; |
| 3725 |
;; .................... |
| 3726 |
|
| 3727 |
;; Unconditional branches. |
| 3728 |
|
| 3729 |
(define_insn "jump" |
| 3730 |
[(set (pc) (label_ref (match_operand 0 "" "")))] |
| 3731 |
"" |
| 3732 |
{ |
| 3733 |
/* Hopefully this does not happen often as this is going |
| 3734 |
to clobber $ra and muck up the return stack predictors. */ |
| 3735 |
if (get_attr_length (insn) == 8) |
| 3736 |
return "jump\t%l0,ra"; |
| 3737 |
|
| 3738 |
return "j\t%l0"; |
| 3739 |
} |
| 3740 |
[(set_attr "type" "jump") |
| 3741 |
(set_attr "mode" "none")]) |
| 3742 |
|
| 3743 |
(define_expand "indirect_jump" |
| 3744 |
[(set (pc) (match_operand 0 "register_operand"))] |
| 3745 |
"" |
| 3746 |
{ |
| 3747 |
if (is_zicfilp_p ()) |
| 3748 |
emit_insn (gen_set_lpl (Pmode, const0_rtx)); |
| 3749 |
|
| 3750 |
operands[0] = force_reg (Pmode, operands[0]); |
| 3751 |
if (is_zicfilp_p ()) |
| 3752 |
emit_use (gen_rtx_REG (Pmode, T2_REGNUM)); |
| 3753 |
|
| 3754 |
if (Pmode == SImode) |
| 3755 |
emit_jump_insn (gen_indirect_jumpsi (operands[0])); |
| 3756 |
else |
| 3757 |
emit_jump_insn (gen_indirect_jumpdi (operands[0])); |
| 3758 |
|
| 3759 |
DONE; |
| 3760 |
}) |
| 3761 |
|
| 3762 |
(define_insn "indirect_jump<mode>" |
| 3763 |
[(set (pc) (match_operand:P 0 "register_operand" "l"))] |
| 3764 |
"" |
| 3765 |
"jr\t%0" |
| 3766 |
[(set_attr "type" "jalr") |
| 3767 |
(set_attr "mode" "none")]) |
| 3768 |
|
| 3769 |
(define_expand "tablejump" |
| 3770 |
[(set (pc) (match_operand 0 "register_operand" "")) |
| 3771 |
(use (label_ref (match_operand 1 "" "")))] |
| 3772 |
"" |
| 3773 |
{ |
| 3774 |
if (CASE_VECTOR_PC_RELATIVE) |
| 3775 |
operands[0] = expand_simple_binop (Pmode, PLUS, operands[0], |
| 3776 |
gen_rtx_LABEL_REF (Pmode, operands[1]), |
| 3777 |
NULL_RTX, 0, OPTAB_DIRECT); |
| 3778 |
|
| 3779 |
if (is_zicfilp_p ()) |
| 3780 |
{ |
| 3781 |
rtx t2 = RISCV_CALL_ADDRESS_LPAD (GET_MODE (operands[0])); |
| 3782 |
emit_move_insn (t2, operands[0]); |
| 3783 |
|
| 3784 |
if (CASE_VECTOR_PC_RELATIVE && Pmode == DImode) |
| 3785 |
emit_jump_insn (gen_tablejump_cfidi (operands[1])); |
| 3786 |
else |
| 3787 |
emit_jump_insn (gen_tablejump_cfisi (operands[1])); |
| 3788 |
} |
| 3789 |
else |
| 3790 |
{ |
| 3791 |
if (CASE_VECTOR_PC_RELATIVE && Pmode == DImode) |
| 3792 |
emit_jump_insn (gen_tablejumpdi (operands[0], operands[1])); |
| 3793 |
else |
| 3794 |
emit_jump_insn (gen_tablejumpsi (operands[0], operands[1])); |
| 3795 |
} |
| 3796 |
DONE; |
| 3797 |
}) |
| 3798 |
|
| 3799 |
(define_insn "tablejump<mode>" |
| 3800 |
[(set (pc) (match_operand:GPR 0 "register_operand" "l")) |
| 3801 |
(use (label_ref (match_operand 1 "" "")))] |
| 3802 |
"!is_zicfilp_p ()" |
| 3803 |
"jr\t%0" |
| 3804 |
[(set_attr "type" "jalr") |
| 3805 |
(set_attr "mode" "none")]) |
| 3806 |
|
| 3807 |
(define_insn "tablejump_cfi<mode>" |
| 3808 |
[(set (pc) (reg:GPR T2_REGNUM)) |
| 3809 |
(use (label_ref (match_operand 0 "")))] |
| 3810 |
"is_zicfilp_p ()" |
| 3811 |
"jr\tt2" |
| 3812 |
[(set_attr "type" "jalr") |
| 3813 |
(set_attr "mode" "none")]) |
| 3814 |
|
| 3815 |
;; |
| 3816 |
;; .................... |
| 3817 |
;; |
| 3818 |
;; Function prologue/epilogue |
| 3819 |
;; |
| 3820 |
;; .................... |
| 3821 |
;; |
| 3822 |
|
| 3823 |
(define_expand "prologue" |
| 3824 |
[(const_int 1)] |
| 3825 |
"" |
| 3826 |
{ |
| 3827 |
riscv_expand_prologue (); |
| 3828 |
DONE; |
| 3829 |
}) |
| 3830 |
|
| 3831 |
;; Block any insns from being moved before this point, since the |
| 3832 |
;; profiling call to mcount can use various registers that aren't |
| 3833 |
;; saved or used to pass arguments. |
| 3834 |
|
| 3835 |
(define_insn "blockage" |
| 3836 |
[(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)] |
| 3837 |
"" |
| 3838 |
"" |
| 3839 |
[(set_attr "type" "ghost") |
| 3840 |
(set_attr "mode" "none")]) |
| 3841 |
|
| 3842 |
(define_expand "epilogue" |
| 3843 |
[(const_int 2)] |
| 3844 |
"" |
| 3845 |
{ |
| 3846 |
riscv_expand_epilogue (NORMAL_RETURN); |
| 3847 |
DONE; |
| 3848 |
}) |
| 3849 |
|
| 3850 |
(define_expand "sibcall_epilogue" |
| 3851 |
[(const_int 2)] |
| 3852 |
"" |
| 3853 |
{ |
| 3854 |
riscv_expand_epilogue (SIBCALL_RETURN); |
| 3855 |
DONE; |
| 3856 |
}) |
| 3857 |
|
| 3858 |
;; Trivial return. Make it look like a normal return insn as that |
| 3859 |
;; allows jump optimizations to work better. |
| 3860 |
|
| 3861 |
(define_expand "return" |
| 3862 |
[(simple_return)] |
| 3863 |
"riscv_can_use_return_insn ()" |
| 3864 |
"") |
| 3865 |
|
| 3866 |
(define_insn "simple_return" |
| 3867 |
[(simple_return)] |
| 3868 |
"" |
| 3869 |
{ |
| 3870 |
return riscv_output_return (); |
| 3871 |
} |
| 3872 |
[(set_attr "type" "jalr") |
| 3873 |
(set_attr "mode" "none")]) |
| 3874 |
|
| 3875 |
;; Normal return. |
| 3876 |
|
| 3877 |
(define_insn "simple_return_internal" |
| 3878 |
[(simple_return) |
| 3879 |
(use (match_operand 0 "pmode_register_operand" ""))] |
| 3880 |
"" |
| 3881 |
"jr\t%0" |
| 3882 |
[(set_attr "type" "jalr") |
| 3883 |
(set_attr "mode" "none")]) |
| 3884 |
|
| 3885 |
;; This is used in compiling the unwind routines. |
| 3886 |
(define_expand "eh_return" |
| 3887 |
[(use (match_operand 0 "general_operand"))] |
| 3888 |
"" |
| 3889 |
{ |
| 3890 |
if (GET_MODE (operands[0]) != word_mode) |
| 3891 |
operands[0] = convert_to_mode (word_mode, operands[0], 0); |
| 3892 |
if (TARGET_64BIT) |
| 3893 |
emit_insn (gen_eh_set_lr_di (operands[0])); |
| 3894 |
else |
| 3895 |
emit_insn (gen_eh_set_lr_si (operands[0])); |
| 3896 |
|
| 3897 |
emit_jump_insn (gen_eh_return_internal ()); |
| 3898 |
emit_barrier (); |
| 3899 |
DONE; |
| 3900 |
}) |
| 3901 |
|
| 3902 |
;; Clobber the return address on the stack. We can't expand this |
| 3903 |
;; until we know where it will be put in the stack frame. |
| 3904 |
|
| 3905 |
(define_insn "eh_set_lr_si" |
| 3906 |
[(unspec [(match_operand:SI 0 "register_operand" "r")] UNSPEC_EH_RETURN) |
| 3907 |
(clobber (match_scratch:SI 1 "=&r"))] |
| 3908 |
"! TARGET_64BIT" |
| 3909 |
"#" |
| 3910 |
[(set_attr "type" "jump")]) |
| 3911 |
|
| 3912 |
(define_insn "eh_set_lr_di" |
| 3913 |
[(unspec [(match_operand:DI 0 "register_operand" "r")] UNSPEC_EH_RETURN) |
| 3914 |
(clobber (match_scratch:DI 1 "=&r"))] |
| 3915 |
"TARGET_64BIT" |
| 3916 |
"#" |
| 3917 |
[(set_attr "type" "jump")]) |
| 3918 |
|
| 3919 |
(define_split |
| 3920 |
[(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN) |
| 3921 |
(clobber (match_scratch 1))] |
| 3922 |
"reload_completed" |
| 3923 |
[(const_int 0)] |
| 3924 |
{ |
| 3925 |
riscv_set_return_address (operands[0], operands[1]); |
| 3926 |
DONE; |
| 3927 |
}) |
| 3928 |
|
| 3929 |
(define_insn_and_split "eh_return_internal" |
| 3930 |
[(eh_return)] |
| 3931 |
"" |
| 3932 |
"#" |
| 3933 |
"epilogue_completed" |
| 3934 |
[(const_int 0)] |
| 3935 |
"riscv_expand_epilogue (EXCEPTION_RETURN); DONE;" |
| 3936 |
[(set_attr "type" "ret")]) |
| 3937 |
|
| 3938 |
;; |
| 3939 |
;; .................... |
| 3940 |
;; |
| 3941 |
;; FUNCTION CALLS |
| 3942 |
;; |
| 3943 |
;; .................... |
| 3944 |
|
| 3945 |
(define_expand "sibcall" |
| 3946 |
[(parallel [(call (match_operand 0 "") |
| 3947 |
(match_operand 1 "")) |
| 3948 |
(use (unspec:SI [ |
| 3949 |
(match_operand 2 "const_int_operand") |
| 3950 |
] UNSPEC_CALLEE_CC))])] |
| 3951 |
"" |
| 3952 |
{ |
| 3953 |
rtx target = riscv_legitimize_call_address (XEXP (operands[0], 0)); |
| 3954 |
emit_call_insn (gen_sibcall_internal (target, operands[1], operands[2])); |
| 3955 |
DONE; |
| 3956 |
}) |
| 3957 |
|
| 3958 |
(define_insn "sibcall_internal" |
| 3959 |
[(call (mem:SI (match_operand 0 "call_insn_operand" "j,S,U")) |
| 3960 |
(match_operand 1 "" "")) |
| 3961 |
(use (unspec:SI [ |
| 3962 |
(match_operand 2 "const_int_operand") |
| 3963 |
] UNSPEC_CALLEE_CC))] |
| 3964 |
"SIBLING_CALL_P (insn)" |
| 3965 |
"@ |
| 3966 |
jr\t%0 |
| 3967 |
tail\t%0 |
| 3968 |
tail\t%0@plt" |
| 3969 |
[(set_attr "type" "call")]) |
| 3970 |
|
| 3971 |
(define_expand "sibcall_value" |
| 3972 |
[(parallel [(set (match_operand 0 "") |
| 3973 |
(call (match_operand 1 "") |
| 3974 |
(match_operand 2 ""))) |
| 3975 |
(use (unspec:SI [ |
| 3976 |
(match_operand 3 "const_int_operand") |
| 3977 |
] UNSPEC_CALLEE_CC))])] |
| 3978 |
"" |
| 3979 |
{ |
| 3980 |
rtx target = riscv_legitimize_call_address (XEXP (operands[1], 0)); |
| 3981 |
emit_call_insn (gen_sibcall_value_internal (operands[0], target, operands[2], |
| 3982 |
operands[3])); |
| 3983 |
DONE; |
| 3984 |
}) |
| 3985 |
|
| 3986 |
(define_insn "sibcall_value_internal" |
| 3987 |
[(set (match_operand 0 "" "") |
| 3988 |
(call (mem:SI (match_operand 1 "call_insn_operand" "j,S,U")) |
| 3989 |
(match_operand 2 "" ""))) |
| 3990 |
(use (unspec:SI [ |
| 3991 |
(match_operand 3 "const_int_operand") |
| 3992 |
] UNSPEC_CALLEE_CC))] |
| 3993 |
"SIBLING_CALL_P (insn)" |
| 3994 |
"@ |
| 3995 |
jr\t%1 |
| 3996 |
tail\t%1 |
| 3997 |
tail\t%1@plt" |
| 3998 |
[(set_attr "type" "call")]) |
| 3999 |
|
| 4000 |
(define_expand "call" |
| 4001 |
[(parallel [(call (match_operand 0 "") |
| 4002 |
(match_operand 1 "")) |
| 4003 |
(use (unspec:SI [ |
| 4004 |
(match_operand 2 "const_int_operand") |
| 4005 |
] UNSPEC_CALLEE_CC))])] |
| 4006 |
"" |
| 4007 |
{ |
| 4008 |
rtx target = riscv_legitimize_call_address (XEXP (operands[0], 0)); |
| 4009 |
emit_call_insn (gen_call_internal (target, operands[1], operands[2])); |
| 4010 |
DONE; |
| 4011 |
}) |
| 4012 |
|
| 4013 |
(define_insn "call_internal" |
| 4014 |
[(call (mem:SI (match_operand 0 "call_insn_operand" "l,S,U")) |
| 4015 |
(match_operand 1 "" "")) |
| 4016 |
(use (unspec:SI [ |
| 4017 |
(match_operand 2 "const_int_operand") |
| 4018 |
] UNSPEC_CALLEE_CC)) |
| 4019 |
(clobber (reg:SI RETURN_ADDR_REGNUM))] |
| 4020 |
"" |
| 4021 |
"@ |
| 4022 |
jalr\t%0 |
| 4023 |
call\t%0 |
| 4024 |
call\t%0@plt" |
| 4025 |
[(set_attr "type" "call")]) |
| 4026 |
|
| 4027 |
(define_expand "call_value" |
| 4028 |
[(parallel [(set (match_operand 0 "") |
| 4029 |
(call (match_operand 1 "") |
| 4030 |
(match_operand 2 ""))) |
| 4031 |
(use (unspec:SI [ |
| 4032 |
(match_operand 3 "const_int_operand") |
| 4033 |
] UNSPEC_CALLEE_CC))])] |
| 4034 |
"" |
| 4035 |
{ |
| 4036 |
rtx target = riscv_legitimize_call_address (XEXP (operands[1], 0)); |
| 4037 |
emit_call_insn (gen_call_value_internal (operands[0], target, operands[2], |
| 4038 |
operands[3])); |
| 4039 |
DONE; |
| 4040 |
}) |
| 4041 |
|
| 4042 |
(define_insn "call_value_internal" |
| 4043 |
[(set (match_operand 0 "" "") |
| 4044 |
(call (mem:SI (match_operand 1 "call_insn_operand" "l,S,U")) |
| 4045 |
(match_operand 2 "" ""))) |
| 4046 |
(use (unspec:SI [ |
| 4047 |
(match_operand 3 "const_int_operand") |
| 4048 |
] UNSPEC_CALLEE_CC)) |
| 4049 |
(clobber (reg:SI RETURN_ADDR_REGNUM))] |
| 4050 |
"" |
| 4051 |
"@ |
| 4052 |
jalr\t%1 |
| 4053 |
call\t%1 |
| 4054 |
call\t%1@plt" |
| 4055 |
[(set_attr "type" "call")]) |
| 4056 |
|
| 4057 |
;; Call subroutine returning any type. |
| 4058 |
|
| 4059 |
(define_expand "untyped_call" |
| 4060 |
[(parallel [(call (match_operand 0 "") |
| 4061 |
(const_int 0)) |
| 4062 |
(match_operand 1 "") |
| 4063 |
(match_operand 2 "")])] |
| 4064 |
"" |
| 4065 |
{ |
| 4066 |
int i; |
| 4067 |
|
| 4068 |
/* Untyped calls always use the RISCV_CC_BASE calling convention. */ |
| 4069 |
emit_call_insn (gen_call (operands[0], const0_rtx, |
| 4070 |
gen_int_mode (RISCV_CC_BASE, SImode))); |
| 4071 |
|
| 4072 |
for (i = 0; i < XVECLEN (operands[2], 0); i++) |
| 4073 |
{ |
| 4074 |
rtx set = XVECEXP (operands[2], 0, i); |
| 4075 |
riscv_emit_move (SET_DEST (set), SET_SRC (set)); |
| 4076 |
} |
| 4077 |
|
| 4078 |
emit_insn (gen_blockage ()); |
| 4079 |
DONE; |
| 4080 |
}) |
| 4081 |
|
| 4082 |
(define_insn "nop" |
| 4083 |
[(const_int 0)] |
| 4084 |
"" |
| 4085 |
"nop" |
| 4086 |
[(set_attr "type" "nop") |
| 4087 |
(set_attr "mode" "none")]) |
| 4088 |
|
| 4089 |
(define_insn "trap" |
| 4090 |
[(trap_if (const_int 1) (const_int 0))] |
| 4091 |
"" |
| 4092 |
"ebreak" |
| 4093 |
[(set_attr "type" "trap")]) |
| 4094 |
|
| 4095 |
;; Must use the registers that we save to prevent the rename reg optimization |
| 4096 |
;; pass from using them before the gpr_save pattern when shrink wrapping |
| 4097 |
;; occurs. See bug 95252 for instance. |
| 4098 |
|
| 4099 |
(define_insn "gpr_save" |
| 4100 |
[(match_parallel 1 "gpr_save_operation" |
| 4101 |
[(unspec_volatile [(match_operand 0 "const_int_operand")] |
| 4102 |
UNSPECV_GPR_SAVE)])] |
| 4103 |
"" |
| 4104 |
"call\tt0,__riscv_save_%0" |
| 4105 |
[(set_attr "type" "call")]) |
| 4106 |
|
| 4107 |
(define_insn "gpr_restore" |
| 4108 |
[(unspec_volatile [(match_operand 0 "const_int_operand")] UNSPECV_GPR_RESTORE)] |
| 4109 |
"" |
| 4110 |
"tail\t__riscv_restore_%0" |
| 4111 |
[(set_attr "type" "call")]) |
| 4112 |
|
| 4113 |
(define_insn "gpr_restore_return" |
| 4114 |
[(return) |
| 4115 |
(use (match_operand 0 "pmode_register_operand" "")) |
| 4116 |
(const_int 0)] |
| 4117 |
"" |
| 4118 |
"" |
| 4119 |
[(set_attr "type" "ret")]) |
| 4120 |
|
| 4121 |
(define_insn "riscv_frcsr" |
| 4122 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 4123 |
(unspec_volatile:SI [(const_int 0)] UNSPECV_FRCSR))] |
| 4124 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 4125 |
"frcsr\t%0" |
| 4126 |
[(set_attr "type" "fmove")]) |
| 4127 |
|
| 4128 |
(define_insn "riscv_fscsr" |
| 4129 |
[(unspec_volatile [(match_operand:SI 0 "register_operand" "r")] UNSPECV_FSCSR)] |
| 4130 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 4131 |
"fscsr\t%0" |
| 4132 |
[(set_attr "type" "fmove")]) |
| 4133 |
|
| 4134 |
(define_insn "riscv_frflags" |
| 4135 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 4136 |
(unspec_volatile:SI [(const_int 0)] UNSPECV_FRFLAGS))] |
| 4137 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 4138 |
"frflags\t%0" |
| 4139 |
[(set_attr "type" "fmove")]) |
| 4140 |
|
| 4141 |
(define_insn "riscv_fsflags" |
| 4142 |
[(unspec_volatile [(match_operand:SI 0 "csr_operand" "rK")] UNSPECV_FSFLAGS)] |
| 4143 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 4144 |
"fsflags%i0\t%0" |
| 4145 |
[(set_attr "type" "fmove")]) |
| 4146 |
|
| 4147 |
(define_insn "*riscv_fsnvsnan<mode>2" |
| 4148 |
[(unspec_volatile [(match_operand:ANYF 0 "register_operand" "f") |
| 4149 |
(match_operand:ANYF 1 "register_operand" "f")] |
| 4150 |
UNSPECV_FSNVSNAN)] |
| 4151 |
"TARGET_HARD_FLOAT || TARGET_ZFINX" |
| 4152 |
"feq.<fmt>\tzero,%0,%1" |
| 4153 |
[(set_attr "type" "fcmp") |
| 4154 |
(set_attr "mode" "<UNITMODE>")]) |
| 4155 |
|
| 4156 |
(define_insn "riscv_mret" |
| 4157 |
[(return) |
| 4158 |
(unspec_volatile [(const_int 0)] UNSPECV_MRET)] |
| 4159 |
"" |
| 4160 |
"mret" |
| 4161 |
[(set_attr "type" "ret")]) |
| 4162 |
|
| 4163 |
(define_insn "riscv_sret" |
| 4164 |
[(return) |
| 4165 |
(unspec_volatile [(const_int 0)] UNSPECV_SRET)] |
| 4166 |
"" |
| 4167 |
"sret" |
| 4168 |
[(set_attr "type" "ret")]) |
| 4169 |
|
| 4170 |
(define_insn "riscv_uret" |
| 4171 |
[(return) |
| 4172 |
(unspec_volatile [(const_int 0)] UNSPECV_URET)] |
| 4173 |
"" |
| 4174 |
"uret" |
| 4175 |
[(set_attr "type" "ret")]) |
| 4176 |
|
| 4177 |
(define_insn "stack_tie<mode>" |
| 4178 |
[(set (mem:BLK (scratch)) |
| 4179 |
(unspec:BLK [(match_operand:X 0 "register_operand" "r") |
| 4180 |
(match_operand:X 1 "register_operand" "r")] |
| 4181 |
UNSPEC_TIE))] |
| 4182 |
"!rtx_equal_p (operands[0], operands[1])" |
| 4183 |
"" |
| 4184 |
[(set_attr "type" "ghost") |
| 4185 |
(set_attr "length" "0")] |
| 4186 |
) |
| 4187 |
|
| 4188 |
(define_expand "save_stack_nonlocal" |
| 4189 |
[(set (match_operand 0 "memory_operand") |
| 4190 |
(match_operand 1 "register_operand"))] |
| 4191 |
"" |
| 4192 |
{ |
| 4193 |
rtx stack_slot; |
| 4194 |
|
| 4195 |
if (need_shadow_stack_push_pop_p ()) |
| 4196 |
{ |
| 4197 |
/* Copy shadow stack pointer to the first slot |
| 4198 |
and stack pointer to the second slot. */ |
| 4199 |
rtx ssp_slot = adjust_address (operands[0], word_mode, 0); |
| 4200 |
stack_slot = adjust_address (operands[0], Pmode, UNITS_PER_WORD); |
| 4201 |
|
| 4202 |
rtx reg_ssp = force_reg (word_mode, const0_rtx); |
| 4203 |
emit_insn (gen_ssrdp (word_mode, reg_ssp)); |
| 4204 |
emit_move_insn (ssp_slot, reg_ssp); |
| 4205 |
} |
| 4206 |
else |
| 4207 |
stack_slot = adjust_address (operands[0], Pmode, 0); |
| 4208 |
emit_move_insn (stack_slot, operands[1]); |
| 4209 |
DONE; |
| 4210 |
}) |
| 4211 |
|
| 4212 |
;; This fixes a failure with gcc.c-torture/execute/pr64242.c at -O2 for a |
| 4213 |
;; 32-bit target when using -mtune=sifive-7-series. The first sched pass |
| 4214 |
;; runs before register elimination, and we have a non-obvious dependency |
| 4215 |
;; between a use of the soft fp and a set of the hard fp. We fix this by |
| 4216 |
;; emitting a clobber using the hard fp between the two insns. |
| 4217 |
(define_expand "restore_stack_nonlocal" |
| 4218 |
[(match_operand 0 "register_operand") |
| 4219 |
(match_operand 1 "memory_operand")] |
| 4220 |
"" |
| 4221 |
{ |
| 4222 |
rtx stack_slot; |
| 4223 |
|
| 4224 |
if (need_shadow_stack_push_pop_p ()) |
| 4225 |
{ |
| 4226 |
rtx t0 = gen_rtx_REG (Pmode, RISCV_PROLOGUE_TEMP_REGNUM); |
| 4227 |
/* Restore shadow stack pointer from the first slot |
| 4228 |
and stack pointer from the second slot. */ |
| 4229 |
rtx ssp_slot = adjust_address (operands[1], word_mode, 0); |
| 4230 |
stack_slot = adjust_address (operands[1], Pmode, UNITS_PER_WORD); |
| 4231 |
|
| 4232 |
/* Get the current shadow stack pointer. */ |
| 4233 |
rtx cur_ssp = force_reg (word_mode, const0_rtx); |
| 4234 |
emit_insn (gen_ssrdp (word_mode, cur_ssp)); |
| 4235 |
|
| 4236 |
/* Compare and jump over adjustment code. */ |
| 4237 |
rtx noadj_label = gen_label_rtx (); |
| 4238 |
emit_cmp_and_jump_insns (cur_ssp, const0_rtx, EQ, NULL_RTX, |
| 4239 |
word_mode, 1, noadj_label); |
| 4240 |
|
| 4241 |
rtx loop_label = gen_label_rtx (); |
| 4242 |
emit_label (loop_label); |
| 4243 |
LABEL_NUSES (loop_label) = 1; |
| 4244 |
|
| 4245 |
/* Check if current ssp less than jump buffer ssp, |
| 4246 |
so no loop is needed. */ |
| 4247 |
emit_cmp_and_jump_insns (ssp_slot, cur_ssp, LE, NULL_RTX, |
| 4248 |
ptr_mode, 1, noadj_label); |
| 4249 |
|
| 4250 |
/* Advance by a maximum of 4K at a time to avoid unwinding |
| 4251 |
past bounds of the shadow stack. */ |
| 4252 |
rtx reg_4096 = force_reg (word_mode, GEN_INT (4096)); |
| 4253 |
rtx cmp_ssp = gen_reg_rtx (word_mode); |
| 4254 |
cmp_ssp = expand_simple_binop (ptr_mode, MINUS, |
| 4255 |
ssp_slot, cur_ssp, |
| 4256 |
cmp_ssp, 1, OPTAB_DIRECT); |
| 4257 |
|
| 4258 |
/* Update curr_ssp from jump buffer ssp. */ |
| 4259 |
emit_move_insn (cur_ssp, ssp_slot); |
| 4260 |
emit_insn (gen_write_ssp (word_mode, cur_ssp)); |
| 4261 |
emit_jump_insn (gen_jump (loop_label)); |
| 4262 |
emit_barrier (); |
| 4263 |
|
| 4264 |
/* Adjust the ssp in a loop. */ |
| 4265 |
rtx cmp_4k_label = gen_label_rtx (); |
| 4266 |
emit_label (cmp_4k_label); |
| 4267 |
LABEL_NUSES (cmp_4k_label) = 1; |
| 4268 |
|
| 4269 |
/* Add 4k for curr_ssp. */ |
| 4270 |
cur_ssp = expand_simple_binop (ptr_mode, PLUS, |
| 4271 |
cur_ssp, reg_4096, |
| 4272 |
cur_ssp, 1, OPTAB_DIRECT); |
| 4273 |
emit_insn (gen_write_ssp (word_mode, cur_ssp)); |
| 4274 |
emit_insn (gen_sspush (Pmode, t0)); |
| 4275 |
emit_insn (gen_sspopchk (Pmode, t0)); |
| 4276 |
emit_jump_insn (gen_jump (loop_label)); |
| 4277 |
emit_barrier (); |
| 4278 |
|
| 4279 |
emit_label (noadj_label); |
| 4280 |
LABEL_NUSES (noadj_label) = 1; |
| 4281 |
} |
| 4282 |
else |
| 4283 |
stack_slot = adjust_address (operands[1], Pmode, 0); |
| 4284 |
|
| 4285 |
emit_move_insn (operands[0], stack_slot); |
| 4286 |
/* Prevent the following hard fp restore from being moved before the move |
| 4287 |
insn above which uses a copy of the soft fp reg. */ |
| 4288 |
emit_clobber (gen_rtx_MEM (BLKmode, hard_frame_pointer_rtx)); |
| 4289 |
DONE; |
| 4290 |
}) |
| 4291 |
|
| 4292 |
;; Named pattern for expanding thread pointer reference. |
| 4293 |
(define_expand "get_thread_pointer<mode>" |
| 4294 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 4295 |
(reg:P TP_REGNUM))] |
| 4296 |
"" |
| 4297 |
{}) |
| 4298 |
|
| 4299 |
;; Named patterns for stack smashing protection. |
| 4300 |
|
| 4301 |
(define_expand "stack_protect_set" |
| 4302 |
[(match_operand 0 "memory_operand") |
| 4303 |
(match_operand 1 "memory_operand")] |
| 4304 |
"" |
| 4305 |
{ |
| 4306 |
machine_mode mode = GET_MODE (operands[0]); |
| 4307 |
if (riscv_stack_protector_guard == SSP_TLS) |
| 4308 |
{ |
| 4309 |
rtx reg = gen_rtx_REG (Pmode, riscv_stack_protector_guard_reg); |
| 4310 |
rtx offset = GEN_INT (riscv_stack_protector_guard_offset); |
| 4311 |
rtx addr = gen_rtx_PLUS (Pmode, reg, offset); |
| 4312 |
operands[1] = gen_rtx_MEM (Pmode, addr); |
| 4313 |
} |
| 4314 |
|
| 4315 |
emit_insn ((mode == DImode |
| 4316 |
? gen_stack_protect_set_di |
| 4317 |
: gen_stack_protect_set_si) (operands[0], operands[1])); |
| 4318 |
DONE; |
| 4319 |
}) |
| 4320 |
|
| 4321 |
;; DO NOT SPLIT THIS PATTERN. It is important for security reasons that the |
| 4322 |
;; canary value does not live beyond the life of this sequence. |
| 4323 |
(define_insn "stack_protect_set_<mode>" |
| 4324 |
[(set (match_operand:GPR 0 "memory_operand" "=m") |
| 4325 |
(unspec:GPR [(match_operand:GPR 1 "memory_operand" "m")] |
| 4326 |
UNSPEC_SSP_SET)) |
| 4327 |
(set (match_scratch:GPR 2 "=&r") (const_int 0))] |
| 4328 |
"" |
| 4329 |
"<load>\t%2, %1\;<store>\t%2, %0\;li\t%2, 0" |
| 4330 |
[(set_attr "type" "multi") |
| 4331 |
(set_attr "length" "12")]) |
| 4332 |
|
| 4333 |
(define_expand "stack_protect_test" |
| 4334 |
[(match_operand 0 "memory_operand") |
| 4335 |
(match_operand 1 "memory_operand") |
| 4336 |
(match_operand 2)] |
| 4337 |
"" |
| 4338 |
{ |
| 4339 |
rtx result; |
| 4340 |
machine_mode mode = GET_MODE (operands[0]); |
| 4341 |
|
| 4342 |
result = gen_reg_rtx(mode); |
| 4343 |
if (riscv_stack_protector_guard == SSP_TLS) |
| 4344 |
{ |
| 4345 |
rtx reg = gen_rtx_REG (Pmode, riscv_stack_protector_guard_reg); |
| 4346 |
rtx offset = GEN_INT (riscv_stack_protector_guard_offset); |
| 4347 |
rtx addr = gen_rtx_PLUS (Pmode, reg, offset); |
| 4348 |
operands[1] = gen_rtx_MEM (Pmode, addr); |
| 4349 |
} |
| 4350 |
emit_insn ((mode == DImode |
| 4351 |
? gen_stack_protect_test_di |
| 4352 |
: gen_stack_protect_test_si) (result, |
| 4353 |
operands[0], |
| 4354 |
operands[1])); |
| 4355 |
|
| 4356 |
rtx cond = gen_rtx_EQ (VOIDmode, result, const0_rtx); |
| 4357 |
emit_jump_insn (gen_cbranch4 (mode, cond, result, const0_rtx, operands[2])); |
| 4358 |
|
| 4359 |
DONE; |
| 4360 |
}) |
| 4361 |
|
| 4362 |
(define_insn "stack_protect_test_<mode>" |
| 4363 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 4364 |
(unspec:GPR [(match_operand:GPR 1 "memory_operand" "m") |
| 4365 |
(match_operand:GPR 2 "memory_operand" "m")] |
| 4366 |
UNSPEC_SSP_TEST)) |
| 4367 |
(clobber (match_scratch:GPR 3 "=&r"))] |
| 4368 |
"" |
| 4369 |
"<load>\t%3, %1\;<load>\t%0, %2\;xor\t%0, %3, %0\;li\t%3, 0" |
| 4370 |
[(set_attr "type" "multi") |
| 4371 |
(set_attr "length" "12")]) |
| 4372 |
|
| 4373 |
(define_insn "riscv_clean_<mode>" |
| 4374 |
[(unspec_volatile:X [(match_operand:X 0 "register_operand" "r")] |
| 4375 |
UNSPECV_CLEAN)] |
| 4376 |
"TARGET_ZICBOM" |
| 4377 |
"cbo.clean\t%a0" |
| 4378 |
[(set_attr "type" "store")] |
| 4379 |
) |
| 4380 |
|
| 4381 |
(define_insn "riscv_flush_<mode>" |
| 4382 |
[(unspec_volatile:X [(match_operand:X 0 "register_operand" "r")] |
| 4383 |
UNSPECV_FLUSH)] |
| 4384 |
"TARGET_ZICBOM" |
| 4385 |
"cbo.flush\t%a0" |
| 4386 |
[(set_attr "type" "store")] |
| 4387 |
) |
| 4388 |
|
| 4389 |
(define_insn "riscv_inval_<mode>" |
| 4390 |
[(unspec_volatile:X [(match_operand:X 0 "register_operand" "r")] |
| 4391 |
UNSPECV_INVAL)] |
| 4392 |
"TARGET_ZICBOM" |
| 4393 |
"cbo.inval\t%a0" |
| 4394 |
[(set_attr "type" "store")] |
| 4395 |
) |
| 4396 |
|
| 4397 |
(define_insn "riscv_zero_<mode>" |
| 4398 |
[(unspec_volatile:X [(match_operand:X 0 "register_operand" "r")] |
| 4399 |
UNSPECV_ZERO)] |
| 4400 |
"TARGET_ZICBOZ" |
| 4401 |
"cbo.zero\t%a0" |
| 4402 |
[(set_attr "type" "store")] |
| 4403 |
) |
| 4404 |
|
| 4405 |
(define_insn "prefetch" |
| 4406 |
[(prefetch (match_operand 0 "prefetch_operand" "Qr") |
| 4407 |
(match_operand 1 "imm5_operand" "i") |
| 4408 |
(match_operand 2 "const_int_operand" "n"))] |
| 4409 |
"TARGET_ZICBOP" |
| 4410 |
{ |
| 4411 |
switch (INTVAL (operands[1])) |
| 4412 |
{ |
| 4413 |
case 0: |
| 4414 |
case 2: return TARGET_ZIHINTNTL ? "%L2prefetch.r\t%a0" : "prefetch.r\t%a0"; |
| 4415 |
case 1: return TARGET_ZIHINTNTL ? "%L2prefetch.w\t%a0" : "prefetch.w\t%a0"; |
| 4416 |
default: gcc_unreachable (); |
| 4417 |
} |
| 4418 |
} |
| 4419 |
[(set_attr "type" "store") |
| 4420 |
(set (attr "length") (if_then_else (and (match_test "TARGET_ZIHINTNTL") |
| 4421 |
(match_test "IN_RANGE (INTVAL (operands[2]), 0, 2)")) |
| 4422 |
(const_string "8") |
| 4423 |
(const_string "4")))]) |
| 4424 |
|
| 4425 |
(define_insn "riscv_prefetchi_<mode>" |
| 4426 |
[(unspec_volatile:X [(match_operand:X 0 "prefetch_operand" "Q") |
| 4427 |
(match_operand:X 1 "imm5_operand" "i")] |
| 4428 |
UNSPECV_PREI)] |
| 4429 |
"TARGET_ZICBOP" |
| 4430 |
"prefetch.i\t%a0" |
| 4431 |
[(set_attr "type" "store")]) |
| 4432 |
|
| 4433 |
(define_expand "extv<mode>" |
| 4434 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 4435 |
(sign_extract:GPR (match_operand:GPR 1 "register_operand" "r") |
| 4436 |
(match_operand 2 "const_int_operand") |
| 4437 |
(match_operand 3 "const_int_operand")))] |
| 4438 |
"TARGET_XTHEADBB" |
| 4439 |
) |
| 4440 |
|
| 4441 |
(define_expand "extzv<mode>" |
| 4442 |
[(set (match_operand:GPR 0 "register_operand" "=r") |
| 4443 |
(zero_extract:GPR (match_operand:GPR 1 "register_operand" "r") |
| 4444 |
(match_operand 2 "const_int_operand") |
| 4445 |
(match_operand 3 "const_int_operand")))] |
| 4446 |
"TARGET_XTHEADBB" |
| 4447 |
{ |
| 4448 |
if (TARGET_XTHEADBB |
| 4449 |
&& (INTVAL (operands[2]) < 8) && (INTVAL (operands[3]) == 0)) |
| 4450 |
FAIL; |
| 4451 |
}) |
| 4452 |
|
| 4453 |
(define_expand "maddhisi4" |
| 4454 |
[(set (match_operand:SI 0 "register_operand") |
| 4455 |
(plus:SI |
| 4456 |
(mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand")) |
| 4457 |
(sign_extend:SI (match_operand:HI 2 "register_operand"))) |
| 4458 |
(match_operand:SI 3 "register_operand")))] |
| 4459 |
"TARGET_XTHEADMAC" |
| 4460 |
) |
| 4461 |
|
| 4462 |
(define_expand "msubhisi4" |
| 4463 |
[(set (match_operand:SI 0 "register_operand") |
| 4464 |
(minus:SI |
| 4465 |
(match_operand:SI 3 "register_operand") |
| 4466 |
(mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand")) |
| 4467 |
(sign_extend:SI (match_operand:HI 2 "register_operand")))))] |
| 4468 |
"TARGET_XTHEADMAC" |
| 4469 |
) |
| 4470 |
|
| 4471 |
;; String compare with length insn. |
| 4472 |
;; Argument 0 is the target (result) |
| 4473 |
;; Argument 1 is the source1 |
| 4474 |
;; Argument 2 is the source2 |
| 4475 |
;; Argument 3 is the length |
| 4476 |
;; Argument 4 is the alignment |
| 4477 |
|
| 4478 |
(define_expand "cmpstrnsi" |
| 4479 |
[(parallel [(set (match_operand:SI 0) |
| 4480 |
(compare:SI (match_operand:BLK 1) |
| 4481 |
(match_operand:BLK 2))) |
| 4482 |
(use (match_operand:SI 3)) |
| 4483 |
(use (match_operand:SI 4))])] |
| 4484 |
"riscv_inline_strncmp && !optimize_size |
| 4485 |
&& (TARGET_ZBB || TARGET_XTHEADBB || TARGET_VECTOR)" |
| 4486 |
{ |
| 4487 |
rtx temp = gen_reg_rtx (word_mode); |
| 4488 |
if (riscv_expand_strcmp (temp, operands[1], operands[2], |
| 4489 |
operands[3], operands[4])) |
| 4490 |
{ |
| 4491 |
if (TARGET_64BIT) |
| 4492 |
{ |
| 4493 |
temp = gen_lowpart (SImode, temp); |
| 4494 |
SUBREG_PROMOTED_VAR_P (temp) = 1; |
| 4495 |
SUBREG_PROMOTED_SET (temp, SRP_SIGNED); |
| 4496 |
} |
| 4497 |
emit_move_insn (operands[0], temp); |
| 4498 |
DONE; |
| 4499 |
} |
| 4500 |
else |
| 4501 |
FAIL; |
| 4502 |
}) |
| 4503 |
|
| 4504 |
;; String compare insn. |
| 4505 |
;; Argument 0 is the target (result) |
| 4506 |
;; Argument 1 is the source1 |
| 4507 |
;; Argument 2 is the source2 |
| 4508 |
;; Argument 3 is the alignment |
| 4509 |
|
| 4510 |
(define_expand "cmpstrsi" |
| 4511 |
[(parallel [(set (match_operand:SI 0) |
| 4512 |
(compare:SI (match_operand:BLK 1) |
| 4513 |
(match_operand:BLK 2))) |
| 4514 |
(use (match_operand:SI 3))])] |
| 4515 |
"riscv_inline_strcmp && !optimize_size |
| 4516 |
&& (TARGET_ZBB || TARGET_XTHEADBB || TARGET_VECTOR)" |
| 4517 |
{ |
| 4518 |
rtx temp = gen_reg_rtx (word_mode); |
| 4519 |
if (riscv_expand_strcmp (temp, operands[1], operands[2], |
| 4520 |
NULL_RTX, operands[3])) |
| 4521 |
{ |
| 4522 |
if (TARGET_64BIT) |
| 4523 |
{ |
| 4524 |
temp = gen_lowpart (SImode, temp); |
| 4525 |
SUBREG_PROMOTED_VAR_P (temp) = 1; |
| 4526 |
SUBREG_PROMOTED_SET (temp, SRP_SIGNED); |
| 4527 |
} |
| 4528 |
emit_move_insn (operands[0], temp); |
| 4529 |
DONE; |
| 4530 |
} |
| 4531 |
else |
| 4532 |
FAIL; |
| 4533 |
}) |
| 4534 |
|
| 4535 |
;; Search character in string (generalization of strlen). |
| 4536 |
;; Argument 0 is the resulting offset |
| 4537 |
;; Argument 1 is the string |
| 4538 |
;; Argument 2 is the search character |
| 4539 |
;; Argument 3 is the alignment |
| 4540 |
|
| 4541 |
(define_expand "strlen<mode>" |
| 4542 |
[(set (match_operand:X 0 "register_operand") |
| 4543 |
(unspec:X [(match_operand:BLK 1 "general_operand") |
| 4544 |
(match_operand:SI 2 "const_int_operand") |
| 4545 |
(match_operand:SI 3 "const_int_operand")] |
| 4546 |
UNSPEC_STRLEN))] |
| 4547 |
"riscv_inline_strlen && !optimize_size |
| 4548 |
&& (TARGET_ZBB || TARGET_XTHEADBB || TARGET_VECTOR)" |
| 4549 |
{ |
| 4550 |
rtx search_char = operands[2]; |
| 4551 |
|
| 4552 |
if (search_char != const0_rtx) |
| 4553 |
FAIL; |
| 4554 |
|
| 4555 |
if (riscv_expand_strlen (operands[0], operands[1], operands[2], operands[3])) |
| 4556 |
DONE; |
| 4557 |
else |
| 4558 |
FAIL; |
| 4559 |
}) |
| 4560 |
|
| 4561 |
(define_insn "*large_load_address" |
| 4562 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 4563 |
(mem:DI (match_operand 1 "pcrel_symbol_operand" "")))] |
| 4564 |
"TARGET_64BIT && riscv_cmodel == CM_LARGE" |
| 4565 |
"ld\t%0,%1" |
| 4566 |
[(set_attr "type" "load") |
| 4567 |
(set (attr "length") (const_int 8))]) |
| 4568 |
|
| 4569 |
;; The AND is redunant here. It always turns off the high 32 bits and the |
| 4570 |
;; low number of bits equal to the shift count. Those upper 32 bits will be |
| 4571 |
;; reset by the SIGN_EXTEND at the end. |
| 4572 |
;; |
| 4573 |
;; One could argue combine should have realized this and simplified what it |
| 4574 |
;; presented to the backend. But we can obviously cope with what it gave us. |
| 4575 |
(define_insn_and_split "" |
| 4576 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 4577 |
(sign_extend:DI |
| 4578 |
(plus:SI (subreg:SI |
| 4579 |
(and:DI |
| 4580 |
(ashift:DI (match_operand:DI 1 "register_operand" "r") |
| 4581 |
(match_operand 2 "const_int_operand" "n")) |
| 4582 |
(match_operand 3 "const_int_operand" "n")) 0) |
| 4583 |
(match_operand:SI 4 "register_operand" "r")))) |
| 4584 |
(clobber (match_scratch:DI 5 "=&r"))] |
| 4585 |
"TARGET_64BIT |
| 4586 |
&& (INTVAL (operands[3]) | ((1 << INTVAL (operands[2])) - 1)) == 0xffffffff" |
| 4587 |
"#" |
| 4588 |
"&& reload_completed" |
| 4589 |
[(set (match_dup 5) (ashift:DI (match_dup 1) (match_dup 2))) |
| 4590 |
(set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 6) (match_dup 4))))] |
| 4591 |
"{ operands[6] = gen_lowpart (SImode, operands[5]); }" |
| 4592 |
[(set_attr "type" "arith")]) |
| 4593 |
|
| 4594 |
(define_expand "usadd<mode>3" |
| 4595 |
[(match_operand:ANYI 0 "register_operand") |
| 4596 |
(match_operand:ANYI 1 "reg_or_int_operand") |
| 4597 |
(match_operand:ANYI 2 "reg_or_int_operand")] |
| 4598 |
"" |
| 4599 |
{ |
| 4600 |
riscv_expand_usadd (operands[0], operands[1], operands[2]); |
| 4601 |
DONE; |
| 4602 |
} |
| 4603 |
) |
| 4604 |
|
| 4605 |
(define_expand "ssadd<mode>3" |
| 4606 |
[(match_operand:ANYI 0 "register_operand") |
| 4607 |
(match_operand:ANYI 1 "register_operand") |
| 4608 |
(match_operand:ANYI 2 "register_operand")] |
| 4609 |
"" |
| 4610 |
{ |
| 4611 |
riscv_expand_ssadd (operands[0], operands[1], operands[2]); |
| 4612 |
DONE; |
| 4613 |
} |
| 4614 |
) |
| 4615 |
|
| 4616 |
(define_expand "ussub<mode>3" |
| 4617 |
[(match_operand:ANYI 0 "register_operand") |
| 4618 |
(match_operand:ANYI 1 "reg_or_int_operand") |
| 4619 |
(match_operand:ANYI 2 "reg_or_int_operand")] |
| 4620 |
"" |
| 4621 |
{ |
| 4622 |
riscv_expand_ussub (operands[0], operands[1], operands[2]); |
| 4623 |
DONE; |
| 4624 |
} |
| 4625 |
) |
| 4626 |
|
| 4627 |
(define_expand "sssub<mode>3" |
| 4628 |
[(match_operand:ANYI 0 "register_operand") |
| 4629 |
(match_operand:ANYI 1 "register_operand") |
| 4630 |
(match_operand:ANYI 2 "register_operand")] |
| 4631 |
"" |
| 4632 |
{ |
| 4633 |
riscv_expand_sssub (operands[0], operands[1], operands[2]); |
| 4634 |
DONE; |
| 4635 |
} |
| 4636 |
) |
| 4637 |
|
| 4638 |
(define_expand "ustrunc<mode><anyi_double_truncated>2" |
| 4639 |
[(match_operand:<ANYI_DOUBLE_TRUNCATED> 0 "register_operand") |
| 4640 |
(match_operand:ANYI_DOUBLE_TRUNC 1 "register_operand")] |
| 4641 |
"" |
| 4642 |
{ |
| 4643 |
riscv_expand_ustrunc (operands[0], operands[1]); |
| 4644 |
DONE; |
| 4645 |
} |
| 4646 |
) |
| 4647 |
|
| 4648 |
(define_expand "sstrunc<mode><anyi_double_truncated>2" |
| 4649 |
[(match_operand:<ANYI_DOUBLE_TRUNCATED> 0 "register_operand") |
| 4650 |
(match_operand:ANYI_DOUBLE_TRUNC 1 "register_operand")] |
| 4651 |
"" |
| 4652 |
{ |
| 4653 |
riscv_expand_sstrunc (operands[0], operands[1]); |
| 4654 |
DONE; |
| 4655 |
} |
| 4656 |
) |
| 4657 |
|
| 4658 |
(define_expand "ustrunc<mode><anyi_quad_truncated>2" |
| 4659 |
[(match_operand:<ANYI_QUAD_TRUNCATED> 0 "register_operand") |
| 4660 |
(match_operand:ANYI_QUAD_TRUNC 1 "register_operand")] |
| 4661 |
"" |
| 4662 |
{ |
| 4663 |
riscv_expand_ustrunc (operands[0], operands[1]); |
| 4664 |
DONE; |
| 4665 |
} |
| 4666 |
) |
| 4667 |
|
| 4668 |
(define_expand "sstrunc<mode><anyi_quad_truncated>2" |
| 4669 |
[(match_operand:<ANYI_QUAD_TRUNCATED> 0 "register_operand") |
| 4670 |
(match_operand:ANYI_QUAD_TRUNC 1 "register_operand")] |
| 4671 |
"" |
| 4672 |
{ |
| 4673 |
riscv_expand_sstrunc (operands[0], operands[1]); |
| 4674 |
DONE; |
| 4675 |
} |
| 4676 |
) |
| 4677 |
|
| 4678 |
(define_expand "ustrunc<mode><anyi_oct_truncated>2" |
| 4679 |
[(match_operand:<ANYI_OCT_TRUNCATED> 0 "register_operand") |
| 4680 |
(match_operand:ANYI_OCT_TRUNC 1 "register_operand")] |
| 4681 |
"" |
| 4682 |
{ |
| 4683 |
riscv_expand_ustrunc (operands[0], operands[1]); |
| 4684 |
DONE; |
| 4685 |
} |
| 4686 |
) |
| 4687 |
|
| 4688 |
(define_expand "sstrunc<mode><anyi_oct_truncated>2" |
| 4689 |
[(match_operand:<ANYI_OCT_TRUNCATED> 0 "register_operand") |
| 4690 |
(match_operand:ANYI_OCT_TRUNC 1 "register_operand")] |
| 4691 |
"" |
| 4692 |
{ |
| 4693 |
riscv_expand_sstrunc (operands[0], operands[1]); |
| 4694 |
DONE; |
| 4695 |
} |
| 4696 |
) |
| 4697 |
|
| 4698 |
;; These are forms of (x << C1) + C2, potentially canonicalized from |
| 4699 |
;; ((x + C2') << C1. Depending on the cost to load C2 vs C2' we may |
| 4700 |
;; want to go ahead and recognize this form as C2 may be cheaper to |
| 4701 |
;; synthesize than C2'. |
| 4702 |
;; |
| 4703 |
;; It might be better to refactor riscv_const_insns a bit so that we |
| 4704 |
;; can have an API that passes integer values around rather than |
| 4705 |
;; constructing a lot of garbage RTL. |
| 4706 |
;; |
| 4707 |
;; The mvconst_internal pattern in effect requires this pattern to |
| 4708 |
;; also be a define_insn_and_split due to insn count costing when |
| 4709 |
;; splitting in combine. |
| 4710 |
(define_insn_and_split "" |
| 4711 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 4712 |
(plus:DI (ashift:DI (match_operand:DI 1 "register_operand" "r") |
| 4713 |
(match_operand 2 "const_int_operand" "n")) |
| 4714 |
(match_operand 3 "const_int_operand" "n"))) |
| 4715 |
(clobber (match_scratch:DI 4 "=&r"))] |
| 4716 |
"(TARGET_64BIT && riscv_const_insns (operands[3], false) == 1)" |
| 4717 |
"#" |
| 4718 |
"&& reload_completed" |
| 4719 |
[(const_int 0)] |
| 4720 |
"{ |
| 4721 |
rtx x = gen_rtx_ASHIFT (DImode, operands[1], operands[2]); |
| 4722 |
emit_insn (gen_rtx_SET (operands[0], x)); |
| 4723 |
|
| 4724 |
/* If the constant fits in a simm12, use it directly as we do not |
| 4725 |
get another good chance to optimize things again. */ |
| 4726 |
if (!SMALL_OPERAND (INTVAL (operands[3]))) |
| 4727 |
emit_move_insn (operands[4], operands[3]); |
| 4728 |
else |
| 4729 |
operands[4] = operands[3]; |
| 4730 |
|
| 4731 |
x = gen_rtx_PLUS (DImode, operands[0], operands[4]); |
| 4732 |
emit_insn (gen_rtx_SET (operands[0], x)); |
| 4733 |
DONE; |
| 4734 |
}" |
| 4735 |
[(set_attr "type" "arith")]) |
| 4736 |
|
| 4737 |
(define_insn_and_split "" |
| 4738 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 4739 |
(sign_extend:DI (plus:SI (ashift:SI |
| 4740 |
(match_operand:SI 1 "register_operand" "r") |
| 4741 |
(match_operand 2 "const_int_operand" "n")) |
| 4742 |
(match_operand 3 "const_int_operand" "n")))) |
| 4743 |
(clobber (match_scratch:DI 4 "=&r"))] |
| 4744 |
"(TARGET_64BIT && riscv_const_insns (operands[3], false) == 1)" |
| 4745 |
"#" |
| 4746 |
"&& reload_completed" |
| 4747 |
[(const_int 0)] |
| 4748 |
"{ |
| 4749 |
operands[1] = gen_lowpart (DImode, operands[1]); |
| 4750 |
operands[5] = gen_lowpart (SImode, operands[0]); |
| 4751 |
operands[6] = gen_lowpart (SImode, operands[4]); |
| 4752 |
|
| 4753 |
rtx x = gen_rtx_ASHIFT (DImode, operands[1], operands[2]); |
| 4754 |
emit_insn (gen_rtx_SET (operands[0], x)); |
| 4755 |
|
| 4756 |
/* If the constant fits in a simm12, use it directly as we do not |
| 4757 |
get another good chance to optimize things again. */ |
| 4758 |
if (!SMALL_OPERAND (INTVAL (operands[3]))) |
| 4759 |
emit_move_insn (operands[4], operands[3]); |
| 4760 |
else |
| 4761 |
operands[6] = operands[3]; |
| 4762 |
|
| 4763 |
x = gen_rtx_PLUS (SImode, operands[5], operands[6]); |
| 4764 |
x = gen_rtx_SIGN_EXTEND (DImode, x); |
| 4765 |
emit_insn (gen_rtx_SET (operands[0], x)); |
| 4766 |
DONE; |
| 4767 |
}" |
| 4768 |
[(set_attr "type" "arith")]) |
| 4769 |
|
| 4770 |
;; Shadow stack |
| 4771 |
|
| 4772 |
(define_insn "@sspush<mode>" |
| 4773 |
[(unspec_volatile [(match_operand:P 0 "x1x5_operand" "r")] UNSPECV_SSPUSH)] |
| 4774 |
"TARGET_ZICFISS" |
| 4775 |
"sspush\t%0" |
| 4776 |
[(set_attr "type" "arith") |
| 4777 |
(set_attr "mode" "<MODE>")]) |
| 4778 |
|
| 4779 |
(define_insn "@sspopchk<mode>" |
| 4780 |
[(unspec_volatile [(match_operand:P 0 "x1x5_operand" "r")] UNSPECV_SSPOPCHK)] |
| 4781 |
"TARGET_ZICFISS" |
| 4782 |
"sspopchk\t%0" |
| 4783 |
[(set_attr "type" "arith") |
| 4784 |
(set_attr "mode" "<MODE>")]) |
| 4785 |
|
| 4786 |
(define_insn "@ssrdp<mode>" |
| 4787 |
[(set (match_operand:P 0 "register_operand" "=r") |
| 4788 |
(unspec_volatile [(const_int 0)] UNSPECV_SSRDP))] |
| 4789 |
"TARGET_ZICFISS" |
| 4790 |
"ssrdp\t%0" |
| 4791 |
[(set_attr "type" "arith") |
| 4792 |
(set_attr "mode" "<MODE>")]) |
| 4793 |
|
| 4794 |
(define_insn "@write_ssp<mode>" |
| 4795 |
[(unspec_volatile [(match_operand:P 0 "register_operand" "r")] UNSPECV_SSP)] |
| 4796 |
"TARGET_ZICFISS" |
| 4797 |
"csrw\tssp, %0" |
| 4798 |
[(set_attr "type" "arith") |
| 4799 |
(set_attr "mode" "<MODE>")]) |
| 4800 |
|
| 4801 |
;; Lading pad. |
| 4802 |
|
| 4803 |
(define_insn "lpad" |
| 4804 |
[(unspec_volatile [(match_operand 0 "immediate_operand" "i")] UNSPECV_LPAD)] |
| 4805 |
"TARGET_ZICFILP" |
| 4806 |
"lpad\t%0" |
| 4807 |
[(set_attr "type" "auipc")]) |
| 4808 |
|
| 4809 |
(define_insn "@set_lpl<mode>" |
| 4810 |
[(set (reg:GPR T2_REGNUM) |
| 4811 |
(unspec_volatile [(match_operand:GPR 0 "immediate_operand" "i")] UNSPECV_SETLPL))] |
| 4812 |
"TARGET_ZICFILP" |
| 4813 |
"lui\tt2,%0" |
| 4814 |
[(set_attr "type" "const") |
| 4815 |
(set_attr "mode" "<MODE>")]) |
| 4816 |
|
| 4817 |
(define_insn "lpad_align" |
| 4818 |
[(unspec_volatile [(const_int 0)] UNSPECV_LPAD_ALIGN)] |
| 4819 |
"TARGET_ZICFILP" |
| 4820 |
".align 2" |
| 4821 |
[(set_attr "type" "nop")]) |
| 4822 |
|
| 4823 |
(define_insn "@set_guarded<mode>" |
| 4824 |
[(set (reg:GPR T2_REGNUM) |
| 4825 |
(unspec_volatile [(match_operand:GPR 0 "register_operand" "r")] UNSPECV_SET_GUARDED))] |
| 4826 |
"TARGET_ZICFILP" |
| 4827 |
"mv\tt2,%0" |
| 4828 |
[(set_attr "type" "move") |
| 4829 |
(set_attr "mode" "<MODE>")]) |
| 4830 |
|
| 4831 |
(include "bitmanip.md") |
| 4832 |
(include "crypto.md") |
| 4833 |
(include "sync.md") |
| 4834 |
(include "sync-rvwmo.md") |
| 4835 |
(include "sync-ztso.md") |
| 4836 |
(include "peephole.md") |
| 4837 |
(include "pic.md") |
| 4838 |
(include "generic.md") |
| 4839 |
(include "sifive-7.md") |
| 4840 |
(include "sifive-p400.md") |
| 4841 |
(include "sifive-p600.md") |
| 4842 |
(include "thead.md") |
| 4843 |
(include "generic-vector-ooo.md") |
| 4844 |
(include "generic-ooo.md") |
| 4845 |
(include "vector.md") |
| 4846 |
(include "vector-crypto.md") |
| 4847 |
(include "vector-bfloat16.md") |
| 4848 |
(include "zicond.md") |
| 4849 |
(include "sfb.md") |
| 4850 |
(include "zc.md") |
| 4851 |
(include "corev.md") |
| 4852 |
(include "xiangshan.md") |