1 ;; Constraint definitions for Synopsys DesignWare ARC.
2 ;; Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
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)
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.
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/>.
20 ;; Register constraints
22 ; Most instructions accept arbitrary core registers for their inputs, even
23 ; if the core register in question cannot be written to, like the multiply
24 ; result registers of ARC600.
25 ; First, define a class for core registers that can be read cheaply. This
26 ; is most or all core registers for ARC600, but only r0-r31 for ARC700
27 (define_register_constraint "c" "GENERAL_REGS"
28 "Legacy, core register @code{r0}-@code{r31}, @code{ap},@code{pcl}")
30 ; All core regs - e.g. for when we must have a way to reload a register.
31 (define_register_constraint "Rac" "GENERAL_REGS"
32 "Legacy, core register @code{r0}-@code{r60}, @code{ap},@code{pcl}")
34 ; Some core registers (.e.g lp_count) aren't general registers because they
35 ; can't be used as the destination of a multi-cycle operation like
36 ; load and/or multiply, yet they are still writable in the sense that
37 ; register-register moves and single-cycle arithmetic (e.g "add", "and",
38 ; but not "mpy") can write to them.
39 (define_register_constraint "w" "GENERAL_REGS"
40 "Legacy, writable core register: @code{r0}-@code{r31}, @code{r60},
41 nonfixed core register")
43 (define_register_constraint "W" "GENERAL_REGS"
44 "Legacy, writable core register except @code{LP_COUNT} (@code{r60}):
45 @code{r0}-@code{r31}, nonfixed core register")
47 (define_constraint "l"
49 Loop count register @code{r60}"
50 (and (match_code "reg")
51 (match_test "REGNO (op) == LP_COUNT")))
53 (define_register_constraint "x" "R0_REGS"
54 "@code{R0} register.")
56 (define_register_constraint "q" "ARCOMPACT16_REGS"
57 "Registers usable in ARCompact 16-bit instructions: @code{r0}-@code{r3},
58 @code{r12}-@code{r15}")
60 ; NPS400 bitfield instructions require registers from the r0-r3,r12-r15
61 ; range, and thus we need a register class and constraint that works
62 ; independently of size optimization.
63 (define_register_constraint
64 "Rrq" "TARGET_RRQ_CLASS ? ARCOMPACT16_REGS : NO_REGS"
65 "Registers usable in NPS400 bitfield instructions: @code{r0}-@code{r3},
66 @code{r12}-@code{r15}")
68 (define_register_constraint "D" "DOUBLE_REGS"
69 "ARC FPX (dpfp) 64-bit registers. @code{D0}, @code{D1}")
71 (define_register_constraint "d" "SIMD_DMA_CONFIG_REGS"
73 ARC SIMD DMA configuration registers @code{di0}-@code{di7},
74 @code{do0}-@code{do7}")
76 (define_register_constraint "v" "SIMD_VR_REGS"
77 "ARC SIMD 128-bit registers @code{VR0}-@code{VR23}")
79 ; We could allow call-saved registers for sibling calls if we restored them
80 ; in the delay slot of the call. However, that would not allow to adjust the
81 ; stack pointer afterwards, so the call-saved register would have to be
82 ; restored from a call-used register that was just loaded with the value
83 ; before. So sticking to call-used registers for sibcalls will likely
84 ; generate better code overall.
85 (define_register_constraint "Rsc" "SIBCALL_REGS"
87 Sibling call register")
89 ;; Integer constraints
91 (define_constraint "I"
93 A signed 12-bit integer constant."
94 (and (match_code "const_int")
95 (match_test "SIGNED_INT12 (ival)")))
97 (define_constraint "K"
99 A 3-bit unsigned integer constant"
100 (and (match_code "const_int")
101 (match_test "UNSIGNED_INT3 (ival)")))
103 (define_constraint "L"
105 A 6-bit unsigned integer constant"
106 (and (match_code "const_int")
107 (match_test "UNSIGNED_INT6 (ival)")))
109 (define_constraint "CnL"
111 One's complement of a 6-bit unsigned integer constant"
112 (and (match_code "const_int")
113 (match_test "UNSIGNED_INT6 (~ival)")))
115 (define_constraint "C16"
117 A 16-bit signed integer constant"
118 (and (match_code "const_int")
119 (match_test "SIGNED_INT16 (ival)")))
121 (define_constraint "M"
123 A 5-bit unsigned integer constant"
124 (and (match_code "const_int")
125 (match_test "UNSIGNED_INT5 (ival)")))
127 (define_constraint "N"
130 (and (match_code "const_int")
131 (match_test "IS_ONE (ival)")))
133 (define_constraint "O"
135 A 7-bit unsigned integer constant"
136 (and (match_code "const_int")
137 (match_test "UNSIGNED_INT7 (ival)")))
139 (define_constraint "P"
141 An 8-bit unsigned integer constant"
142 (and (match_code "const_int")
143 (match_test "UNSIGNED_INT8 (ival)")))
145 (define_constraint "C_0"
148 (and (match_code "const_int")
149 (match_test "ival == 0")))
151 (define_constraint "Cn0"
154 (and (match_code "const_int")
155 (match_test "ival <= 0")))
157 (define_constraint "CM4"
159 A valid 5-bit unsigned stack offset for a short add"
160 (and (match_code "const_int")
161 (match_test "!(ival & ~124)")))
163 (define_constraint "CP4"
165 A valid 5-bit unsigned stack offset for a short sub"
166 (and (match_code "const_int")
167 (match_test "!(-ival & ~124)")))
169 (define_constraint "C0p"
172 (and (match_code "const_int")
173 (match_test "IS_POWEROF2_P (ival & 0xffffffff)")))
175 (define_constraint "C1p"
177 constant such that x+1 is a power of two, and x != 0"
178 (and (match_code "const_int")
179 (match_test "ival && IS_POWEROF2_P (ival + 1)")))
181 (define_constraint "C2p"
183 constant such that (~x)+1 is a power of two, and x < -1"
184 (and (match_code "const_int")
185 (match_test "TARGET_V2
187 && IS_POWEROF2_P ((~ival) + 1)")))
189 (define_constraint "C3p"
191 constant int used to select xbfu a,b,u6 instruction. The values accepted are 1 and 2."
192 (and (match_code "const_int")
193 (match_test "((ival == 1) || (ival == 2))")))
195 (define_constraint "Ccp"
197 constant such that ~x (one's Complement) is a power of two"
198 (and (match_code "const_int")
199 (match_test "IS_POWEROF2_P (~ival)")))
201 (define_constraint "Cux"
203 constant such that AND gives an unsigned extension"
204 (and (match_code "const_int")
205 (match_test "ival == 0xff || ival == 0xffff")))
207 (define_constraint "Chs"
209 constant for a highpart that can be checked with a shift (asr.f 0,rn,m)"
210 (and (match_code "const_int")
211 (match_test "IS_POWEROF2_P (-ival)")
212 (match_test "TARGET_BARREL_SHIFTER")))
214 (define_constraint "Clo"
216 constant that fits into 16 lower bits, for movl"
217 (and (match_code "const_int")
218 (match_test "TARGET_NPS_BITOPS")
219 (match_test "(ival & ~0xffffU) == 0")))
221 (define_constraint "Chi"
223 constant that fits into 16 higher bits, for movh_i"
224 (and (match_code "const_int")
225 (match_test "TARGET_NPS_BITOPS")
226 (match_test "trunc_int_for_mode (ival >> 16, HImode) << 16 == ival")))
228 (define_constraint "Cbf"
230 a mask for a bit field, for AND using movb_i"
231 (and (match_code "const_int")
232 (match_test "TARGET_NPS_BITOPS")
233 (match_test "IS_POWEROF2_OR_0_P (ival + (ival & -ival))")))
235 (define_constraint "Cbn"
237 a constant integer, valid only if TARGET_NPS_BITOPS is true"
238 (and (match_code "const_int")
239 (match_test "TARGET_NPS_BITOPS")))
241 (define_constraint "C18"
244 (and (match_code "const_int")
245 (match_test "ival == 1 || ival == 2 || ival == 4 || ival == 8")))
247 (define_constraint "Cbi"
249 constant that can be loaded with movbi.cl"
250 (and (match_code "const_int")
251 (match_test "TARGET_NPS_BITOPS")
253 || ((ival & 0xffffffffUL) >> exact_log2 (ival & -ival)
256 (define_constraint "C0x"
258 special const_int pattern used to split ior insns"
259 (and (match_code "const_int")
260 (match_test "optimize_size")
261 (match_test "arc_check_ior_const (ival)")))
263 (define_constraint "Cax"
265 special const_int pattern used to split mov insns"
266 (and (match_code "const_int")
267 (match_test "optimize_size")
268 (match_test "arc_check_mov_const (ival)")))
270 ;; Floating-point constraints
272 (define_constraint "G"
274 A 32-bit constant double value"
275 (and (match_code "const_double")
276 (match_test "arc_double_limm_p (op)")))
278 (define_constraint "H"
280 All const_double values (including 64-bit values)"
281 (and (match_code "const_double")
284 (define_constraint "CfZ"
286 Match a floating-point zero"
287 (and (match_code "const_double")
288 (match_test "op == CONST0_RTX (SFmode)")))
290 ;; Memory constraints
291 (define_memory_constraint "T"
293 A valid memory operand for ARCompact load instructions"
294 (and (match_code "mem")
295 (match_test "compact_memory_operand_p (op, mode, false, false)")))
297 (define_memory_constraint "Uts"
299 A valid memory operand for ARCompact load instructions scaled"
300 (and (match_code "mem")
301 (match_test "compact_memory_operand_p (op, mode, false, TARGET_CODE_DENSITY)")))
303 (define_memory_constraint "S"
305 A valid memory operand for ARCompact store instructions"
306 (and (match_code "mem")
307 (match_test "compact_store_memory_operand (op, VOIDmode)")))
309 (define_memory_constraint "Uex"
311 A valid memory operand for limm-free extend instructions"
312 (and (match_code "mem")
313 (match_test "!cmem_address (XEXP (op, 0), SImode)")
314 (not (match_operand 0 "long_immediate_loadstore_operand"))))
316 (define_memory_constraint "Usd"
318 A valid _small-data_ memory operand for ARCompact instructions"
319 (and (match_code "mem")
320 (match_test "compact_sda_memory_operand (op, VOIDmode, true)")))
322 ; Usc constant is only used for storing long constants, hence we can
323 ; have only [b,s9], and [b] types of addresses.
324 (define_memory_constraint "Usc"
326 A valid memory operand for storing constants"
327 (and (match_code "mem")
328 (match_test "!CONSTANT_P (XEXP (op,0))")))
330 (define_constraint "Us<"
333 (and (match_code "mem")
334 (match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")
335 (match_test "REG_P (XEXP (XEXP (op, 0), 0))")
336 (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
338 (define_constraint "Us>"
340 Stack post-increment"
341 (and (match_code "mem")
342 (match_test "GET_CODE (XEXP (op, 0)) == POST_INC")
343 (match_test "REG_P (XEXP (XEXP (op, 0), 0))")
344 (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
346 (define_constraint "Ucm"
349 (and (match_code "mem")
350 (match_test "TARGET_NPS_CMEM && cmem_address (XEXP (op, 0), VOIDmode)")))
352 ;; General constraints
354 (define_constraint "Cbr"
356 (ior (and (match_code "symbol_ref")
357 (match_test "!arc_is_longcall_p (op)"))
358 (match_code "label_ref")))
360 (define_constraint "Cbp"
361 "predicable branch/call destination"
362 (ior (and (match_code "symbol_ref")
363 (match_test "arc_is_shortcall_p (op)"))
364 (match_code "label_ref")))
366 (define_constraint "Cji"
368 (and (match_code "symbol_ref")
369 (match_test "TARGET_CODE_DENSITY")
370 (match_test "arc_is_jli_call_p (op)")))
372 (define_constraint "Csc"
374 (and (match_code "symbol_ref")
375 (match_test "TARGET_CODE_DENSITY")
376 (match_test "TARGET_EM")
377 (match_test "arc_is_secure_call_p (op)")))
379 (define_constraint "Cpc"
380 "pc-relative constant"
381 (match_test "arc_legitimate_pic_addr_p (op)"))
383 (define_constraint "Clb"
385 (and (match_code "label_ref")
386 (match_test "arc_text_label (as_a <rtx_insn *> (XEXP (op, 0)))")))
388 (define_constraint "Cal"
389 "constant for arithmetic/logical operations"
390 (match_test "immediate_operand (op, VOIDmode) && !arc_legitimate_pic_addr_p (op)"))
392 (define_constraint "C32"
393 "32 bit constant for arithmetic/logical operations"
394 (match_test "immediate_operand (op, VOIDmode)
395 && !arc_legitimate_pic_addr_p (op)
396 && !satisfies_constraint_I (op)"))
398 (define_constraint "Csz"
399 "a 32 bit constant avoided when compiling for size."
400 (match_test "immediate_operand (op, VOIDmode)
401 && !arc_legitimate_pic_addr_p (op)
402 && !(satisfies_constraint_I (op) && optimize_size)"))
404 (define_constraint "Rcb"
406 Stack Pointer register @code{r28} - do not reload into its class"
407 (and (match_code "reg")
408 (match_test "REGNO (op) == 28")))
410 (define_constraint "Rck"
412 blink (usful for push_s / pop_s)"
413 (and (match_code "reg")
414 (match_test "REGNO (op) == 31")))
416 (define_constraint "Rcc"
419 (and (match_code "reg") (match_test "cc_register (op, VOIDmode)")))
421 (define_constraint "Ral"
423 Accumulator register @code{ACCL} - do not reload into its class"
424 (and (match_code "reg")
425 (match_test "REGNO (op) == ACCL_REGNO")))
427 (define_constraint "Q"
429 Integer constant zero"
430 (and (match_code "const_int")
431 (match_test "IS_ZERO (ival)")))
433 (define_constraint "Cm1"
435 Integer signed constant in the interval [-1,6]"
436 (and (match_code "const_int")
437 (match_test "(ival >= -1) && (ival <=6)")
438 (match_test "TARGET_V2")))
440 (define_constraint "Cm2"
442 A signed 9-bit integer constant."
443 (and (match_code "const_int")
444 (match_test "(ival >= -256) && (ival <=255)")))
446 (define_constraint "Cm3"
448 A signed 6-bit integer constant."
449 (and (match_code "const_int")
450 (match_test "(ival >= -32) && (ival <=31)")
451 (match_test "TARGET_V2")))
453 (define_constraint "C62"
455 An unsigned 6-bit integer constant, up to 62."
456 (and (match_code "const_int")
457 (match_test "UNSIGNED_INT6 (ival - 1)")))
459 ;; Memory constraint used for atomic ops.
460 (define_memory_constraint "ATO"
461 "A memory with only a base register"
462 (match_operand 0 "mem_noofs_operand"))
464 (define_constraint "J12"
466 An unsigned 12-bit integer constant."
467 (and (match_code "const_int")
468 (match_test "UNSIGNED_INT12 (ival)")))
470 (define_constraint "J16"
472 An unsigned 16-bit integer constant"
473 (and (match_code "const_int")
474 (match_test "UNSIGNED_INT16 (ival)")))
476 ; Memory addresses suited for code density load ops
477 (define_memory_constraint "Ucd"
479 A valid memory operand for use with code density load ops"
480 (and (match_code "mem")
481 (match_test "compact_memory_operand_p (op, mode, true, false)")
482 (match_test "TARGET_V2")))
484 (define_register_constraint "h"
485 "TARGET_V2 ? AC16_H_REGS : NO_REGS"
486 "5-bit h register set except @code{r30} and @code{r29}:
487 @code{r0}-@code{r31}, nonfixed core register")
489 ; Code density registers
490 (define_register_constraint "Rcd"
491 "TARGET_CODE_DENSITY ? R0R3_CD_REGS : NO_REGS"
493 core register @code{r0}-@code{r3}")
495 (define_register_constraint "Rsd"
496 "TARGET_CODE_DENSITY ? R0R1_CD_REGS : NO_REGS"
498 core register @code{r0}-@code{r1}")
500 (define_register_constraint "Rzd"
501 "TARGET_CODE_DENSITY ? R0_REGS : NO_REGS"
503 @code{r0} register for code density instructions.")
505 (define_constraint "C6u" "@internal
506 A 6-bit unsigned integer constant shifted by x-bit(s)"
507 (and (match_code "const_int")
508 (ior (match_test "UNSIGNED_INT9_SHIFTED (ival,3)")
509 (match_test "UNSIGNED_INT8_SHIFTED (ival,2)")
510 (match_test "UNSIGNED_INT7_SHIFTED (ival,1)")
511 (match_test "UNSIGNED_INT6 (ival)"))))
513 (define_constraint "C6n" "@internal
514 A negative 6-bit integer constant shifted by x-bit(s) used by add."
515 (and (match_code "const_int")
516 (match_test "ival < 0")
517 (match_test "SIGNED_INT10(ival)")
518 (ior (match_test "UNSIGNED_INT9_SHIFTED (-ival,3)")
519 (match_test "UNSIGNED_INT8_SHIFTED (-ival,2)")
520 (match_test "UNSIGNED_INT7_SHIFTED (-ival,1)")
521 (match_test "UNSIGNED_INT6 (-ival)"))))
523 (define_constraint "CIs" "@internal
524 A 12-bit signed integer constant shifted by x-bit(s)"
525 (and (match_code "const_int")
526 (ior (match_test "SIGNED_INT15_SHIFTED (ival,3)")
527 (match_test "SIGNED_INT14_SHIFTED (ival,2)")
528 (match_test "SIGNED_INT13_SHIFTED (ival,1)")
529 (match_test "SIGNED_INT12 (ival)"))))
531 (define_constraint "C4p"
534 (and (match_code "const_int")
535 (match_test "ival == (HOST_WIDE_INT) (HOST_WIDE_INT_M1U << 31)")))