| 1 |
;; Iterators for the machine description for RISC-V |
| 2 |
;; Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
;; This file is part of GCC. |
| 5 |
;; |
| 6 |
;; GCC is free software; you can redistribute it and/or modify it |
| 7 |
;; under the terms of the GNU General Public License as published by |
| 8 |
;; the Free Software Foundation; either version 3, or (at your option) |
| 9 |
;; any later version. |
| 10 |
;; |
| 11 |
;; GCC is distributed in the hope that it will be useful, but |
| 12 |
;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
;; General Public License for more details. |
| 15 |
;; |
| 16 |
;; You should have received a copy of the GNU General Public License |
| 17 |
;; along with GCC; see the file COPYING3. If not see |
| 18 |
;; <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
|
| 21 |
;; ------------------------------------------------------------------- |
| 22 |
;; Mode Iterators |
| 23 |
;; ------------------------------------------------------------------- |
| 24 |
|
| 25 |
;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated |
| 26 |
;; from the same template. |
| 27 |
(define_mode_iterator GPR [SI (DI "TARGET_64BIT")]) |
| 28 |
|
| 29 |
;; A copy of GPR that can be used when a pattern has two independent |
| 30 |
;; modes. |
| 31 |
(define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")]) |
| 32 |
|
| 33 |
;; This mode iterator allows :P to be used for patterns that operate on |
| 34 |
;; pointer-sized quantities. Exactly one of the two alternatives will match. |
| 35 |
(define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")]) |
| 36 |
|
| 37 |
;; Likewise, but for XLEN-sized quantities. |
| 38 |
(define_mode_iterator X [(SI "!TARGET_64BIT") (DI "TARGET_64BIT")]) |
| 39 |
|
| 40 |
;; Likewise, but for XLEN/2 -sized quantities. |
| 41 |
(define_mode_iterator HX [(HI "!TARGET_64BIT") (SI "TARGET_64BIT")]) |
| 42 |
|
| 43 |
;; Branches operate on XLEN-sized quantities, but for RV64 we accept |
| 44 |
;; QImode values so we can force zero-extension. |
| 45 |
(define_mode_iterator BR [(QI "TARGET_64BIT") SI (DI "TARGET_64BIT")]) |
| 46 |
|
| 47 |
;; 32-bit moves for which we provide move patterns. |
| 48 |
(define_mode_iterator MOVE32 [SI]) |
| 49 |
|
| 50 |
;; 64-bit modes for which we provide move patterns. |
| 51 |
(define_mode_iterator MOVE64 [DI DF]) |
| 52 |
|
| 53 |
;; Iterator for sub-32-bit integer modes. |
| 54 |
(define_mode_iterator SHORT [QI HI]) |
| 55 |
|
| 56 |
;; Iterator for HImode constant generation. |
| 57 |
(define_mode_iterator HISI [HI SI]) |
| 58 |
|
| 59 |
;; Iterator for QImode extension patterns. |
| 60 |
(define_mode_iterator SUPERQI [HI SI (DI "TARGET_64BIT")]) |
| 61 |
|
| 62 |
;; Iterator for hardware integer modes narrower than XLEN. |
| 63 |
(define_mode_iterator SUBX [QI HI (SI "TARGET_64BIT")]) |
| 64 |
|
| 65 |
;; Iterator for hardware integer modes narrower than XLEN, same as SUBX. |
| 66 |
(define_mode_iterator SUBX1 [QI HI (SI "TARGET_64BIT")]) |
| 67 |
|
| 68 |
;; Iterator for hardware-supported integer modes. |
| 69 |
(define_mode_iterator ANYI [QI HI SI (DI "TARGET_64BIT")]) |
| 70 |
|
| 71 |
;; Iterator for hardware integer modes narrower than XLEN, same as ANYI. |
| 72 |
(define_mode_iterator ANYI1 [QI HI SI (DI "TARGET_64BIT")]) |
| 73 |
|
| 74 |
(define_mode_iterator ANYI_DOUBLE_TRUNC [HI SI (DI "TARGET_64BIT")]) |
| 75 |
|
| 76 |
(define_mode_iterator ANYI_QUAD_TRUNC [SI (DI "TARGET_64BIT")]) |
| 77 |
|
| 78 |
(define_mode_iterator ANYI_OCT_TRUNC [(DI "TARGET_64BIT")]) |
| 79 |
|
| 80 |
(define_mode_attr ANYI_DOUBLE_TRUNCATED [ |
| 81 |
(HI "QI") (SI "HI") (DI "SI") |
| 82 |
]) |
| 83 |
|
| 84 |
(define_mode_attr ANYI_QUAD_TRUNCATED [ |
| 85 |
(SI "QI") (DI "HI") |
| 86 |
]) |
| 87 |
|
| 88 |
(define_mode_attr ANYI_OCT_TRUNCATED [ |
| 89 |
(DI "QI") |
| 90 |
]) |
| 91 |
|
| 92 |
(define_mode_attr anyi_double_truncated [ |
| 93 |
(HI "qi") (SI "hi") (DI "si") |
| 94 |
]) |
| 95 |
|
| 96 |
(define_mode_attr anyi_quad_truncated [ |
| 97 |
(SI "qi") (DI "hi") |
| 98 |
]) |
| 99 |
|
| 100 |
(define_mode_attr anyi_oct_truncated [ |
| 101 |
(DI "qi") |
| 102 |
]) |
| 103 |
|
| 104 |
;; Iterator for hardware-supported floating-point modes. |
| 105 |
(define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT || TARGET_ZFINX") |
| 106 |
(DF "TARGET_DOUBLE_FLOAT || TARGET_ZDINX") |
| 107 |
(HF "TARGET_ZFH || TARGET_ZHINX")]) |
| 108 |
|
| 109 |
;; Iterator for hardware-supported load/store floating-point modes. |
| 110 |
(define_mode_iterator ANYLSF [(SF "TARGET_HARD_FLOAT || TARGET_ZFINX") |
| 111 |
(DF "TARGET_DOUBLE_FLOAT || TARGET_ZDINX") |
| 112 |
(HF "TARGET_ZFHMIN || TARGET_ZHINXMIN")]) |
| 113 |
|
| 114 |
;; Iterator for floating-point modes that can be loaded into X registers. |
| 115 |
(define_mode_iterator SOFTF [SF (DF "TARGET_64BIT") (HF "TARGET_ZFHMIN")]) |
| 116 |
|
| 117 |
;; Iterator for floating-point modes of BF16. |
| 118 |
(define_mode_iterator HFBF [HF BF]) |
| 119 |
|
| 120 |
;; Conversion between floating-point modes and BF16. |
| 121 |
;; SF to BF16 have hardware instructions. |
| 122 |
(define_mode_iterator FBF [HF DF TF]) |
| 123 |
|
| 124 |
;; ------------------------------------------------------------------- |
| 125 |
;; Mode attributes |
| 126 |
;; ------------------------------------------------------------------- |
| 127 |
|
| 128 |
;; This attribute gives the length suffix for a sign- or zero-extension |
| 129 |
;; instruction. |
| 130 |
(define_mode_attr size [(QI "b") (HI "h")]) |
| 131 |
|
| 132 |
;; Mode attributes for loads. |
| 133 |
(define_mode_attr load [(QI "lb") (HI "lh") (SI "lw") (DI "ld") (HF "flh") (SF "flw") (DF "fld")]) |
| 134 |
|
| 135 |
;; Instruction names for integer loads that aren't explicitly sign or zero |
| 136 |
;; extended. See riscv_output_move and LOAD_EXTEND_OP. |
| 137 |
(define_mode_attr default_load [(QI "lbu") (HI "lhu") (SI "lw") (DI "ld")]) |
| 138 |
|
| 139 |
;; Mode attribute for FP loads into integer registers. |
| 140 |
(define_mode_attr softload [(HF "lh") (SF "lw") (DF "ld")]) |
| 141 |
|
| 142 |
;; Instruction names for stores. |
| 143 |
(define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd") (HF "fsh") (SF "fsw") (DF "fsd")]) |
| 144 |
|
| 145 |
;; Instruction names for FP stores from integer registers. |
| 146 |
(define_mode_attr softstore [(HF "sh") (SF "sw") (DF "sd")]) |
| 147 |
|
| 148 |
;; This attribute gives the best constraint to use for registers of |
| 149 |
;; a given mode. |
| 150 |
(define_mode_attr reg [(SI "d") (DI "d") (CC "d")]) |
| 151 |
|
| 152 |
;; This attribute gives the format suffix for floating-point operations. |
| 153 |
(define_mode_attr fmt [(HF "h") (SF "s") (DF "d")]) |
| 154 |
|
| 155 |
;; This attribute gives the integer suffix for floating-point conversions. |
| 156 |
(define_mode_attr ifmt [(SI "w") (DI "l")]) |
| 157 |
|
| 158 |
;; This attribute gives the format suffix for atomic memory operations. |
| 159 |
(define_mode_attr amo [(SI "w") (DI "d")]) |
| 160 |
|
| 161 |
;; This attribute gives the format suffix for byte and halfword atomic memory operations. |
| 162 |
(define_mode_attr amobh [(QI "b") (HI "h")]) |
| 163 |
|
| 164 |
;; This attribute gives the upper-case mode name for one unit of a |
| 165 |
;; floating-point mode. |
| 166 |
(define_mode_attr UNITMODE [(HF "HF") (SF "SF") (DF "DF")]) |
| 167 |
|
| 168 |
;; This attribute gives the integer mode that has half the size of |
| 169 |
;; the controlling mode. |
| 170 |
(define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) |
| 171 |
|
| 172 |
; bitmanip mode attribute |
| 173 |
(define_mode_attr shiftm1 [(SI "const_si_mask_operand") (DI "const_di_mask_operand")]) |
| 174 |
(define_mode_attr shiftm1p [(SI "DsS") (DI "DsD")]) |
| 175 |
|
| 176 |
; zcmp mode attribute |
| 177 |
(define_mode_attr slot0_offset [(SI "-4") (DI "-8")]) |
| 178 |
(define_mode_attr slot1_offset [(SI "-8") (DI "-16")]) |
| 179 |
(define_mode_attr slot2_offset [(SI "-12") (DI "-24")]) |
| 180 |
(define_mode_attr slot3_offset [(SI "-16") (DI "-32")]) |
| 181 |
(define_mode_attr slot4_offset [(SI "-20") (DI "-40")]) |
| 182 |
(define_mode_attr slot5_offset [(SI "-24") (DI "-48")]) |
| 183 |
(define_mode_attr slot6_offset [(SI "-28") (DI "-56")]) |
| 184 |
(define_mode_attr slot7_offset [(SI "-32") (DI "-64")]) |
| 185 |
(define_mode_attr slot8_offset [(SI "-36") (DI "-72")]) |
| 186 |
(define_mode_attr slot9_offset [(SI "-40") (DI "-80")]) |
| 187 |
(define_mode_attr slot10_offset [(SI "-44") (DI "-88")]) |
| 188 |
(define_mode_attr slot11_offset [(SI "-48") (DI "-96")]) |
| 189 |
(define_mode_attr slot12_offset [(SI "-52") (DI "-104")]) |
| 190 |
|
| 191 |
;; ------------------------------------------------------------------- |
| 192 |
;; Code Iterators |
| 193 |
;; ------------------------------------------------------------------- |
| 194 |
|
| 195 |
;; This code iterator allows signed and unsigned widening multiplications |
| 196 |
;; to use the same template. |
| 197 |
(define_code_iterator any_extend [sign_extend zero_extend]) |
| 198 |
|
| 199 |
;; These code iterators allow unsigned and signed extraction to be generated |
| 200 |
;; from the same template. |
| 201 |
(define_code_iterator any_extract [sign_extract zero_extract]) |
| 202 |
(define_code_attr extract_sidi_shift [(sign_extract "sraiw") |
| 203 |
(zero_extract "srliw")]) |
| 204 |
(define_code_attr extract_shift [(sign_extract "ashiftrt") |
| 205 |
(zero_extract "lshiftrt")]) |
| 206 |
|
| 207 |
;; This code iterator allows the two right shift instructions to be |
| 208 |
;; generated from the same template. |
| 209 |
(define_code_iterator any_shiftrt [ashiftrt lshiftrt]) |
| 210 |
|
| 211 |
;; This code iterator allows the three shift instructions to be generated |
| 212 |
;; from the same template. |
| 213 |
(define_code_iterator any_shift [ashift ashiftrt lshiftrt]) |
| 214 |
|
| 215 |
;; This code iterator allows the three bitwise instructions to be generated |
| 216 |
;; from the same template. |
| 217 |
(define_code_iterator any_bitwise [and ior xor]) |
| 218 |
|
| 219 |
;; This code iterator allows ior and xor instructions to be generated |
| 220 |
;; from the same template. |
| 221 |
(define_code_iterator any_or [ior xor]) |
| 222 |
|
| 223 |
;; This code iterator allows unsigned and signed division to be generated |
| 224 |
;; from the same template. |
| 225 |
(define_code_iterator any_div [div udiv mod umod]) |
| 226 |
|
| 227 |
;; This code iterator allows unsigned and signed modulus to be generated |
| 228 |
;; from the same template. |
| 229 |
(define_code_iterator any_mod [mod umod]) |
| 230 |
|
| 231 |
;; These code iterators allow unsigned and signed divmod to be generated |
| 232 |
;; from the same template. |
| 233 |
(define_code_iterator only_div [div udiv]) |
| 234 |
(define_code_attr paired_mod [(div "mod") (udiv "umod")]) |
| 235 |
|
| 236 |
;; These code iterators allow the signed and unsigned scc operations to use |
| 237 |
;; the same template. |
| 238 |
(define_code_iterator any_gt [gt gtu]) |
| 239 |
(define_code_iterator any_ge [ge geu]) |
| 240 |
(define_code_iterator any_lt [lt ltu]) |
| 241 |
(define_code_iterator any_le [le leu]) |
| 242 |
(define_code_iterator any_eq [eq ne]) |
| 243 |
|
| 244 |
;; Iterators for conditions we can emit a sCC against 0 or a reg directly |
| 245 |
(define_code_iterator scc_0 [eq ne gt gtu]) |
| 246 |
|
| 247 |
; atomics code iterator |
| 248 |
(define_code_iterator any_atomic [plus ior xor and]) |
| 249 |
|
| 250 |
; bitmanip code iterators |
| 251 |
(define_code_iterator bitmanip_bitwise [and ior]) |
| 252 |
|
| 253 |
(define_code_iterator bitmanip_minmax [smin umin smax umax]) |
| 254 |
|
| 255 |
(define_code_iterator clz_ctz_pcnt [clz ctz popcount]) |
| 256 |
|
| 257 |
(define_code_iterator bitmanip_rotate [rotate rotatert]) |
| 258 |
|
| 259 |
;; These code iterators allow the signed and unsigned fix operations to use |
| 260 |
;; the same template. |
| 261 |
(define_code_iterator fix_ops [fix unsigned_fix]) |
| 262 |
|
| 263 |
(define_code_attr fix_uns [(fix "fix") (unsigned_fix "fixuns")]) |
| 264 |
|
| 265 |
|
| 266 |
;; ------------------------------------------------------------------- |
| 267 |
;; Code Attributes |
| 268 |
;; ------------------------------------------------------------------- |
| 269 |
|
| 270 |
;; <u> expands to an empty string when doing a signed operation and |
| 271 |
;; "u" when doing an unsigned operation. |
| 272 |
(define_code_attr u [(sign_extend "") (zero_extend "u") |
| 273 |
(gt "") (gtu "u") |
| 274 |
(ge "") (geu "u") |
| 275 |
(lt "") (ltu "u") |
| 276 |
(le "") (leu "u") |
| 277 |
(fix "") (unsigned_fix "u") |
| 278 |
(div "") (udiv "u") |
| 279 |
(float "") (unsigned_float "u")]) |
| 280 |
|
| 281 |
;; <su> is like <u>, but the signed form expands to "s" rather than "". |
| 282 |
(define_code_attr su [(sign_extend "s") (zero_extend "u")]) |
| 283 |
|
| 284 |
;; <optab> expands to the name of the optab for a particular code. |
| 285 |
(define_code_attr optab [(ashift "ashl") |
| 286 |
(ashiftrt "ashr") |
| 287 |
(lshiftrt "lshr") |
| 288 |
(div "div") |
| 289 |
(mod "mod") |
| 290 |
(udiv "udiv") |
| 291 |
(umod "umod") |
| 292 |
(ge "ge") |
| 293 |
(le "le") |
| 294 |
(gt "gt") |
| 295 |
(lt "lt") |
| 296 |
(eq "eq") |
| 297 |
(ne "ne") |
| 298 |
(ior "ior") |
| 299 |
(xor "xor") |
| 300 |
(and "and") |
| 301 |
(plus "add") |
| 302 |
(minus "sub") |
| 303 |
(smin "smin") |
| 304 |
(smax "smax") |
| 305 |
(umin "umin") |
| 306 |
(umax "umax") |
| 307 |
(mult "mul") |
| 308 |
(not "one_cmpl") |
| 309 |
(neg "neg") |
| 310 |
(abs "abs") |
| 311 |
(sqrt "sqrt") |
| 312 |
(ss_plus "ssadd") |
| 313 |
(us_plus "usadd") |
| 314 |
(ss_minus "sssub") |
| 315 |
(us_minus "ussub") |
| 316 |
(sign_extend "extend") |
| 317 |
(zero_extend "zero_extend") |
| 318 |
(sign_extract "extract") |
| 319 |
(zero_extract "zero_extract") |
| 320 |
(fix "fix_trunc") |
| 321 |
(unsigned_fix "fixuns_trunc")]) |
| 322 |
|
| 323 |
(define_code_attr bit_optab [(ior "bset") |
| 324 |
(xor "binv")]) |
| 325 |
|
| 326 |
;; <or_optab> code attributes |
| 327 |
(define_code_attr or_optab [(ior "ior") |
| 328 |
(xor "xor")]) |
| 329 |
|
| 330 |
;; <insn> expands to the name of the insn that implements a particular code. |
| 331 |
(define_code_attr insn [(ashift "sll") |
| 332 |
(ashiftrt "sra") |
| 333 |
(lshiftrt "srl") |
| 334 |
(div "div") |
| 335 |
(mod "rem") |
| 336 |
(udiv "divu") |
| 337 |
(umod "remu") |
| 338 |
(ior "or") |
| 339 |
(xor "xor") |
| 340 |
(and "and") |
| 341 |
(plus "add") |
| 342 |
(minus "sub") |
| 343 |
(smin "min") |
| 344 |
(smax "max") |
| 345 |
(umin "minu") |
| 346 |
(umax "maxu") |
| 347 |
(mult "mul") |
| 348 |
(not "not") |
| 349 |
(neg "neg") |
| 350 |
(abs "abs") |
| 351 |
(sqrt "sqrt") |
| 352 |
(ss_plus "sadd") |
| 353 |
(us_plus "saddu") |
| 354 |
(ss_minus "ssub") |
| 355 |
(us_minus "ssubu")]) |
| 356 |
|
| 357 |
; atomics code attribute |
| 358 |
(define_code_attr atomic_optab |
| 359 |
[(plus "add") (ior "or") (xor "xor") (and "and")]) |
| 360 |
|
| 361 |
; bitmanip code attributes |
| 362 |
;; Unsigned variant of a min/max optab. |
| 363 |
(define_code_attr uminmax_optab [(smin "umin") |
| 364 |
(smax "umax") |
| 365 |
(umin "umin") |
| 366 |
(umax "umax")]) |
| 367 |
(define_code_attr bitmanip_optab [(smin "smin") |
| 368 |
(smax "smax") |
| 369 |
(umin "umin") |
| 370 |
(umax "umax") |
| 371 |
(clz "clz") |
| 372 |
(ctz "ctz") |
| 373 |
(popcount "popcount") |
| 374 |
(rotate "rotl") |
| 375 |
(rotatert "rotr")]) |
| 376 |
(define_code_attr bitmanip_insn [(smin "min") |
| 377 |
(smax "max") |
| 378 |
(umin "minu") |
| 379 |
(umax "maxu") |
| 380 |
(clz "clz") |
| 381 |
(ctz "ctz") |
| 382 |
(popcount "cpop") |
| 383 |
(rotate "rol") |
| 384 |
(rotatert "ror")]) |
| 385 |
|
| 386 |
;; ------------------------------------------------------------------- |
| 387 |
;; Int Iterators. |
| 388 |
;; ------------------------------------------------------------------- |
| 389 |
|
| 390 |
;; Iterator and attributes for quiet comparisons. |
| 391 |
(define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET]) |
| 392 |
(define_int_attr quiet_pattern [(UNSPEC_FLT_QUIET "lt") (UNSPEC_FLE_QUIET "le")]) |
| 393 |
(define_int_attr QUIET_PATTERN [(UNSPEC_FLT_QUIET "LT") (UNSPEC_FLE_QUIET "LE")]) |
| 394 |
|
| 395 |
(define_int_iterator ROUND [UNSPEC_ROUND UNSPEC_FLOOR UNSPEC_CEIL UNSPEC_BTRUNC UNSPEC_ROUNDEVEN UNSPEC_NEARBYINT]) |
| 396 |
(define_int_attr round_pattern [(UNSPEC_ROUND "round") (UNSPEC_FLOOR "floor") (UNSPEC_CEIL "ceil") |
| 397 |
(UNSPEC_BTRUNC "btrunc") (UNSPEC_ROUNDEVEN "roundeven") (UNSPEC_NEARBYINT "nearbyint")]) |
| 398 |
(define_int_attr round_rm [(UNSPEC_ROUND "rmm") (UNSPEC_FLOOR "rdn") (UNSPEC_CEIL "rup") |
| 399 |
(UNSPEC_BTRUNC "rtz") (UNSPEC_ROUNDEVEN "rne") (UNSPEC_NEARBYINT "dyn")]) |