| 1 |
;; Insn constraint definitions for AVR 8-bit microcontrollers. |
| 2 |
;; Copyright (C) 2006-2025 Free Software Foundation, Inc. |
| 3 |
;; |
| 4 |
;; This file is part of GCC. |
| 5 |
;; |
| 6 |
;; GCC is free software; you can redistribute it and/or modify |
| 7 |
;; it under the terms of the GNU General Public License as published by |
| 8 |
;; the Free Software Foundation; either version 3, or (at your option) |
| 9 |
;; any later version. |
| 10 |
;; |
| 11 |
;; GCC is distributed in the hope that it will be useful, |
| 12 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
;; GNU General Public License for more details. |
| 15 |
;; |
| 16 |
;; You should have received a copy of the GNU General Public License |
| 17 |
;; along with GCC; see the file COPYING3. If not see |
| 18 |
;; <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
;; Register constraints |
| 21 |
|
| 22 |
(define_register_constraint "t" "R0_REG" |
| 23 |
"Temporary register r0") |
| 24 |
|
| 25 |
(define_register_constraint "b" "BASE_POINTER_REGS" |
| 26 |
"Base pointer registers (r28--r31)") |
| 27 |
|
| 28 |
(define_register_constraint "e" "POINTER_REGS" |
| 29 |
"Pointer registers (r26--r31)") |
| 30 |
|
| 31 |
(define_register_constraint "w" "ADDW_REGS" |
| 32 |
"Registers from r24 to r31. These registers |
| 33 |
can be used in @samp{adiw} command.") |
| 34 |
|
| 35 |
(define_register_constraint "d" "LD_REGS" |
| 36 |
"Registers from r16 to r31.") |
| 37 |
|
| 38 |
(define_register_constraint "l" "NO_LD_REGS" |
| 39 |
"Registers from r0 to r15.") |
| 40 |
|
| 41 |
(define_register_constraint "a" "SIMPLE_LD_REGS" |
| 42 |
"Registers from r16 to r23.") |
| 43 |
|
| 44 |
(define_register_constraint "x" "POINTER_X_REGS" |
| 45 |
"Register pair X (r27:r26).") |
| 46 |
|
| 47 |
(define_register_constraint "y" "POINTER_Y_REGS" |
| 48 |
"Register pair Y (r29:r28).") |
| 49 |
|
| 50 |
(define_register_constraint "z" "POINTER_Z_REGS" |
| 51 |
"Register pair Z (r31:r30).") |
| 52 |
|
| 53 |
(define_register_constraint "q" "STACK_REG" |
| 54 |
"Stack pointer register (SPH:SPL).") |
| 55 |
|
| 56 |
(define_constraint "I" |
| 57 |
"Integer constant in the range 0 @dots{} 63." |
| 58 |
(and (match_code "const_int") |
| 59 |
(match_test "ival >= 0 && ival <= 63"))) |
| 60 |
|
| 61 |
(define_constraint "J" |
| 62 |
"Integer constant in the range -63 @dots{} 0." |
| 63 |
(and (match_code "const_int") |
| 64 |
(match_test "ival <= 0 && ival >= -63"))) |
| 65 |
|
| 66 |
(define_constraint "K" |
| 67 |
"Integer constant 2." |
| 68 |
(and (match_code "const_int") |
| 69 |
(match_test "ival == 2"))) |
| 70 |
|
| 71 |
(define_constraint "L" |
| 72 |
"Zero." |
| 73 |
(and (match_code "const_int") |
| 74 |
(match_test "ival == 0"))) |
| 75 |
|
| 76 |
(define_constraint "M" |
| 77 |
"Integer constant in the range 0 @dots{} 0xff." |
| 78 |
(and (match_code "const_int") |
| 79 |
(match_test "ival >= 0 && ival <= 0xff"))) |
| 80 |
|
| 81 |
(define_constraint "N" |
| 82 |
"Constant integer @minus{}1." |
| 83 |
(and (match_code "const_int") |
| 84 |
(match_test "ival == -1"))) |
| 85 |
|
| 86 |
(define_constraint "O" |
| 87 |
"Constant integer 8, 16, or 24." |
| 88 |
(and (match_code "const_int") |
| 89 |
(match_test "ival == 8 || ival == 16 || ival == 24"))) |
| 90 |
|
| 91 |
(define_constraint "P" |
| 92 |
"Constant integer 1." |
| 93 |
(and (match_code "const_int") |
| 94 |
(match_test "ival == 1"))) |
| 95 |
|
| 96 |
(define_constraint "G" |
| 97 |
"Constant float 0." |
| 98 |
(and (match_code "const_double") |
| 99 |
(match_test "op == CONST0_RTX (SFmode)"))) |
| 100 |
|
| 101 |
(define_memory_constraint "Q" |
| 102 |
"A memory address based on Y or Z pointer with displacement." |
| 103 |
(and (match_code "mem") |
| 104 |
(match_test "extra_constraint_Q (op)"))) |
| 105 |
|
| 106 |
(define_constraint "Cm2" |
| 107 |
"Constant integer @minus{}2." |
| 108 |
(and (match_code "const_int") |
| 109 |
(match_test "ival == -2"))) |
| 110 |
|
| 111 |
(define_constraint "C03" |
| 112 |
"Constant integer 3." |
| 113 |
(and (match_code "const_int") |
| 114 |
(match_test "ival == 3"))) |
| 115 |
|
| 116 |
(define_constraint "C04" |
| 117 |
"Constant integer 4." |
| 118 |
(and (match_code "const_int") |
| 119 |
(match_test "ival == 4"))) |
| 120 |
|
| 121 |
(define_constraint "C05" |
| 122 |
"Constant integer 5." |
| 123 |
(and (match_code "const_int") |
| 124 |
(match_test "ival == 5"))) |
| 125 |
|
| 126 |
(define_constraint "C06" |
| 127 |
"Constant integer 6." |
| 128 |
(and (match_code "const_int") |
| 129 |
(match_test "ival == 6"))) |
| 130 |
|
| 131 |
(define_constraint "C07" |
| 132 |
"Constant integer 7." |
| 133 |
(and (match_code "const_int") |
| 134 |
(match_test "ival == 7"))) |
| 135 |
|
| 136 |
(define_constraint "C7c" |
| 137 |
"Constant integer the range 7 @dots{} 12." |
| 138 |
(and (match_code "const_int") |
| 139 |
(match_test "IN_RANGE (ival, 7, 12)"))) |
| 140 |
|
| 141 |
(define_constraint "C14" |
| 142 |
"Constant integer 14." |
| 143 |
(and (match_code "const_int") |
| 144 |
(match_test "ival == 14"))) |
| 145 |
|
| 146 |
(define_constraint "C15" |
| 147 |
"Constant integer 15." |
| 148 |
(and (match_code "const_int") |
| 149 |
(match_test "ival == 15"))) |
| 150 |
|
| 151 |
(define_constraint "C22" |
| 152 |
"Constant integer 22." |
| 153 |
(and (match_code "const_int") |
| 154 |
(match_test "ival == 22"))) |
| 155 |
|
| 156 |
(define_constraint "C23" |
| 157 |
"Constant integer 23." |
| 158 |
(and (match_code "const_int") |
| 159 |
(match_test "ival == 23"))) |
| 160 |
|
| 161 |
(define_constraint "C30" |
| 162 |
"Constant integer 30." |
| 163 |
(and (match_code "const_int") |
| 164 |
(match_test "ival == 30"))) |
| 165 |
|
| 166 |
(define_constraint "C31" |
| 167 |
"Constant integer 31." |
| 168 |
(and (match_code "const_int") |
| 169 |
(match_test "ival == 31"))) |
| 170 |
|
| 171 |
(define_constraint "Ca1" |
| 172 |
"Constant 1-byte integer that allows AND by means of CLT + BLD." |
| 173 |
(and (match_code "const_int") |
| 174 |
(match_test "avr_popcount_each_byte (op, 1, 1<<7)"))) |
| 175 |
|
| 176 |
(define_constraint "Ca2" |
| 177 |
"Constant 2-byte integer that allows AND without clobber register." |
| 178 |
(and (match_code "const_int") |
| 179 |
(match_test "avr_popcount_each_byte (op, 2, (1<<0) | (1<<7) | (1<<8))"))) |
| 180 |
|
| 181 |
(define_constraint "Ca3" |
| 182 |
"Constant 3-byte integer that allows AND without clobber register." |
| 183 |
(and (match_code "const_int") |
| 184 |
(match_test "avr_popcount_each_byte (op, 3, (1<<0) | (1<<7) | (1<<8))"))) |
| 185 |
|
| 186 |
(define_constraint "Ca4" |
| 187 |
"Constant 4-byte integer that allows AND without clobber register." |
| 188 |
(and (match_code "const_int") |
| 189 |
(match_test "avr_popcount_each_byte (op, 4, (1<<0) | (1<<7) | (1<<8))"))) |
| 190 |
|
| 191 |
(define_constraint "Co1" |
| 192 |
"Constant 1-byte integer that allows OR by means of SET + BLD." |
| 193 |
(and (match_code "const_int") |
| 194 |
(match_test "avr_popcount_each_byte (op, 1, 1<<1)"))) |
| 195 |
|
| 196 |
(define_constraint "Co2" |
| 197 |
"Constant 2-byte integer that allows OR without clobber register." |
| 198 |
(and (match_code "const_int") |
| 199 |
(match_test "avr_popcount_each_byte (op, 2, (1<<0) | (1<<1) | (1<<8))"))) |
| 200 |
|
| 201 |
(define_constraint "Co3" |
| 202 |
"Constant 3-byte integer that allows OR without clobber register." |
| 203 |
(and (match_code "const_int") |
| 204 |
(match_test "avr_popcount_each_byte (op, 3, (1<<0) | (1<<1) | (1<<8))"))) |
| 205 |
|
| 206 |
(define_constraint "Co4" |
| 207 |
"Constant 4-byte integer that allows OR without clobber register." |
| 208 |
(and (match_code "const_int") |
| 209 |
(match_test "avr_popcount_each_byte (op, 4, (1<<0) | (1<<1) | (1<<8))"))) |
| 210 |
|
| 211 |
(define_constraint "Cb1" |
| 212 |
"Constant 1-byte integer that has exactly 1 bit set." |
| 213 |
(and (match_code "const_int") |
| 214 |
(match_test "single_one_operand (op, QImode)"))) |
| 215 |
|
| 216 |
(define_constraint "Cb2" |
| 217 |
"Constant 2-byte integer that has exactly 1 bit set." |
| 218 |
(and (match_code "const_int") |
| 219 |
(match_test "single_one_operand (op, HImode)"))) |
| 220 |
|
| 221 |
(define_constraint "Cb3" |
| 222 |
"Constant 3-byte integer that has exactly 1 bit set." |
| 223 |
(and (match_code "const_int") |
| 224 |
(match_test "single_one_operand (op, PSImode)"))) |
| 225 |
|
| 226 |
(define_constraint "Cb4" |
| 227 |
"Constant 4-byte integer that has exactly 1 bit set." |
| 228 |
(and (match_code "const_int") |
| 229 |
(match_test "single_one_operand (op, SImode)"))) |
| 230 |
|
| 231 |
(define_constraint "Cx2" |
| 232 |
"Constant 2-byte integer that allows XOR without clobber register." |
| 233 |
(and (match_code "const_int") |
| 234 |
(match_test "avr_popcount_each_byte (op, 2, (1<<0) | (1<<8))"))) |
| 235 |
|
| 236 |
(define_constraint "Cx3" |
| 237 |
"Constant 3-byte integer that allows XOR without clobber register." |
| 238 |
(and (match_code "const_int") |
| 239 |
(match_test "avr_popcount_each_byte (op, 3, (1<<0) | (1<<8))"))) |
| 240 |
|
| 241 |
(define_constraint "Cx4" |
| 242 |
"Constant 4-byte integer that allows XOR without clobber register." |
| 243 |
(and (match_code "const_int") |
| 244 |
(match_test "avr_popcount_each_byte (op, 4, (1<<0) | (1<<8))"))) |
| 245 |
|
| 246 |
(define_constraint "CX2" |
| 247 |
"Constant 2-byte integer that allows XOR without clobber register but requires a d-register." |
| 248 |
(and (match_code "const_int") |
| 249 |
(match_test "avr_xor_noclobber_dconst (op, 2)"))) |
| 250 |
|
| 251 |
(define_constraint "CX3" |
| 252 |
"Constant 3-byte integer that allows XOR without clobber register but requires a d-register." |
| 253 |
(and (match_code "const_int") |
| 254 |
(match_test "avr_xor_noclobber_dconst (op, 3)"))) |
| 255 |
|
| 256 |
(define_constraint "CX4" |
| 257 |
"Constant 4-byte integer that allows XOR without clobber register but requires a d-register." |
| 258 |
(and (match_code "const_int") |
| 259 |
(match_test "avr_xor_noclobber_dconst (op, 4)"))) |
| 260 |
|
| 261 |
(define_constraint "Csp" |
| 262 |
"Integer constant in the range -11 @dots{} 6." |
| 263 |
(and (match_code "const_int") |
| 264 |
(match_test "IN_RANGE (ival, -11, 6)"))) |
| 265 |
|
| 266 |
(define_constraint "Cxf" |
| 267 |
"32-bit integer constant where at least one nibble is 0xf." |
| 268 |
(and (match_code "const_int") |
| 269 |
(match_test "avr_has_nibble_0xf (op)"))) |
| 270 |
|
| 271 |
(define_constraint "C0f" |
| 272 |
"32-bit integer constant where no nibble equals 0xf." |
| 273 |
(and (match_code "const_int") |
| 274 |
(match_test "!avr_has_nibble_0xf (op)"))) |
| 275 |
|
| 276 |
(define_constraint "Cn8" |
| 277 |
"A negative constant integer in the range @minus{}255 @dots{} @minus{}1." |
| 278 |
(and (match_code "const_int") |
| 279 |
(match_test "IN_RANGE (ival, -255, -1)"))) |
| 280 |
|
| 281 |
(define_constraint "Cp8" |
| 282 |
"A constant integer or symbolic operand that is at least .p2align 8." |
| 283 |
(and (match_code "const_int,symbol_ref,const") |
| 284 |
(match_test "const_0mod256_operand (op, HImode)"))) |
| 285 |
|
| 286 |
(define_constraint "C2a" |
| 287 |
"A constant integer shift offset for a 2-byte ASHIFTRT that's opt to being split." |
| 288 |
(and (match_code "const_int") |
| 289 |
(match_test "avr_split_shift_p (2, ival, ASHIFTRT)"))) |
| 290 |
|
| 291 |
(define_constraint "C2r" |
| 292 |
"A constant integer shift offset for a 2-byte LSHIFTRT that's opt to being split." |
| 293 |
(and (match_code "const_int") |
| 294 |
(match_test "avr_split_shift_p (2, ival, LSHIFTRT)"))) |
| 295 |
|
| 296 |
(define_constraint "C2l" |
| 297 |
"A constant integer shift offset for a 2-byte ASHIFT that's opt to being split." |
| 298 |
(and (match_code "const_int") |
| 299 |
(match_test "avr_split_shift_p (2, ival, ASHIFT)"))) |
| 300 |
|
| 301 |
(define_constraint "C3a" |
| 302 |
"A constant integer shift offset for a 3-byte ASHIFTRT that's opt to being split." |
| 303 |
(and (match_code "const_int") |
| 304 |
(match_test "avr_split_shift_p (3, ival, ASHIFTRT)"))) |
| 305 |
|
| 306 |
(define_constraint "C3r" |
| 307 |
"A constant integer shift offset for a 3-byte LSHIFTRT that's opt to being split." |
| 308 |
(and (match_code "const_int") |
| 309 |
(match_test "avr_split_shift_p (3, ival, LSHIFTRT)"))) |
| 310 |
|
| 311 |
(define_constraint "C3l" |
| 312 |
"A constant integer shift offset for a 3-byte ASHIFT that's opt to being split." |
| 313 |
(and (match_code "const_int") |
| 314 |
(match_test "avr_split_shift_p (3, ival, ASHIFT)"))) |
| 315 |
|
| 316 |
(define_constraint "C4a" |
| 317 |
"A constant integer shift offset for a 4-byte ASHIFTRT that's opt to being split." |
| 318 |
(and (match_code "const_int") |
| 319 |
(match_test "avr_split_shift_p (4, ival, ASHIFTRT)"))) |
| 320 |
|
| 321 |
(define_constraint "C4r" |
| 322 |
"A constant integer shift offset for a 4-byte LSHIFTRT that's opt to being split." |
| 323 |
(and (match_code "const_int") |
| 324 |
(match_test "avr_split_shift_p (4, ival, LSHIFTRT)"))) |
| 325 |
|
| 326 |
(define_constraint "C4l" |
| 327 |
"A constant integer shift offset for a 4-byte ASHIFT that's opt to being split." |
| 328 |
(and (match_code "const_int") |
| 329 |
(match_test "avr_split_shift_p (4, ival, ASHIFT)"))) |
| 330 |
|
| 331 |
(define_constraint "C4R" |
| 332 |
"A constant integer shift offset for a 4-byte LSHIFTRT that's a 3-operand insn independent of options." |
| 333 |
(and (match_code "const_int") |
| 334 |
(match_test "ival == 15 || IN_RANGE (ival, 25, 31)"))) |
| 335 |
|
| 336 |
(define_constraint "C4L" |
| 337 |
"A constant integer shift offset for a 4-byte ASHIFT that's a 3-operand insn independent of options." |
| 338 |
(and (match_code "const_int") |
| 339 |
(match_test "ival == 15 || IN_RANGE (ival, 25, 31)"))) |
| 340 |
|
| 341 |
;; CONST_FIXED is no element of 'n' so cook our own. |
| 342 |
;; "i" or "s" would match but because the insn uses iterators that cover |
| 343 |
;; INT_MODE, "i" or "s" is not always possible. |
| 344 |
|
| 345 |
(define_constraint "Ynn" |
| 346 |
"Fixed-point constant known at compile time." |
| 347 |
(match_code "const_fixed")) |
| 348 |
|
| 349 |
(define_constraint "Y00" |
| 350 |
"Fixed-point or integer constant with bit representation 0x0" |
| 351 |
(and (match_code "const_fixed,const_int") |
| 352 |
(match_test "op == CONST0_RTX (GET_MODE (op))"))) |
| 353 |
|
| 354 |
(define_constraint "Y01" |
| 355 |
"Fixed-point or integer constant with bit representation 0x1" |
| 356 |
(ior (and (match_code "const_fixed") |
| 357 |
(match_test "INTVAL (avr_to_int_mode (op)) == 1")) |
| 358 |
(match_test "satisfies_constraint_P (op)"))) |
| 359 |
|
| 360 |
(define_constraint "Ym1" |
| 361 |
"Fixed-point or integer constant with bit representation -0x1" |
| 362 |
(ior (and (match_code "const_fixed") |
| 363 |
(match_test "INTVAL (avr_to_int_mode (op)) == -1")) |
| 364 |
(match_test "satisfies_constraint_N (op)"))) |
| 365 |
|
| 366 |
(define_constraint "Y02" |
| 367 |
"Fixed-point or integer constant with bit representation 0x2" |
| 368 |
(ior (and (match_code "const_fixed") |
| 369 |
(match_test "INTVAL (avr_to_int_mode (op)) == 2")) |
| 370 |
(match_test "satisfies_constraint_K (op)"))) |
| 371 |
|
| 372 |
(define_constraint "Ym2" |
| 373 |
"Fixed-point or integer constant with bit representation -0x2" |
| 374 |
(ior (and (match_code "const_fixed") |
| 375 |
(match_test "INTVAL (avr_to_int_mode (op)) == -2")) |
| 376 |
(match_test "satisfies_constraint_Cm2 (op)"))) |
| 377 |
|
| 378 |
;; Constraint that's the empty set. Useful with mode and code iterators. |
| 379 |
(define_constraint "Yxx" |
| 380 |
"A constraints that is always false" |
| 381 |
(match_test "false")) |
| 382 |
|
| 383 |
(define_constraint "Yx2" |
| 384 |
"Fixed-point or integer constant not in the range @minus{}2 @dots{} 2" |
| 385 |
(and (ior (match_code "const_int") |
| 386 |
(match_code "const_fixed")) |
| 387 |
(match_test "!IN_RANGE (INTVAL (avr_to_int_mode (op)), -2, 2)"))) |
| 388 |
|
| 389 |
;; Similar to "IJ" used with ADIW/SBIW, but for CONST_FIXED. |
| 390 |
|
| 391 |
(define_constraint "YIJ" |
| 392 |
"Fixed-point constant from @minus{}0x003f to 0x003f." |
| 393 |
(and (match_code "const_fixed") |
| 394 |
(match_test "IN_RANGE (INTVAL (avr_to_int_mode (op)), -63, 63)"))) |
| 395 |
|
| 396 |
;; Similar to "M", but for CONST_FIXED. |
| 397 |
|
| 398 |
(define_constraint "YMM" |
| 399 |
"Fixed-point constant in the range 0 @dots{} 0xff when viewed as CONST_INT." |
| 400 |
(and (match_code "const_fixed") |
| 401 |
(match_test "IN_RANGE (INTVAL (avr_to_int_mode (op)), 0, 0xff)"))) |
| 402 |
|
| 403 |
(define_constraint "Yil" |
| 404 |
"Memory in the lower half of the I/O space." |
| 405 |
(and (match_code "mem") |
| 406 |
(match_test "low_io_address_operand (XEXP (op, 0), Pmode)"))) |