1 ;; Constraint definitions for Synopsys DesignWare ARC.
2 ;; Copyright (C) 2007-2019 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" "TARGET_Q_CLASS ? ARCOMPACT16_REGS : NO_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 "CmL"
117 Two's complement of a 6-bit unsigned integer constant"
118 (and (match_code "const_int")
119 (match_test "UNSIGNED_INT6 (-ival)")))
121 (define_constraint "C16"
123 A 16-bit signed integer constant"
124 (and (match_code "const_int")
125 (match_test "SIGNED_INT16 (ival)")))
127 (define_constraint "M"
129 A 5-bit unsigned integer constant"
130 (and (match_code "const_int")
131 (match_test "UNSIGNED_INT5 (ival)")))
133 (define_constraint "N"
136 (and (match_code "const_int")
137 (match_test "IS_ONE (ival)")))
139 (define_constraint "O"
141 A 7-bit unsigned integer constant"
142 (and (match_code "const_int")
143 (match_test "UNSIGNED_INT7 (ival)")))
145 (define_constraint "P"
147 An 8-bit unsigned integer constant"
148 (and (match_code "const_int")
149 (match_test "UNSIGNED_INT8 (ival)")))
151 (define_constraint "C_0"
154 (and (match_code "const_int")
155 (match_test "ival == 0")))
157 (define_constraint "Cn0"
160 (and (match_code "const_int")
161 (match_test "ival <= 0")))
163 (define_constraint "Cca"
165 Conditional or three-address add / sub constant"
166 (and (match_code "const_int")
167 (match_test "ival == (HOST_WIDE_INT)(HOST_WIDE_INT_M1U << 31)
168 || (ival >= -0x1f8 && ival <= 0x1f8
169 && ((ival >= 0 ? ival : -ival)
170 <= 0x3f * (ival & -ival)))")))
172 ; intersection of "O" and "Cca".
173 (define_constraint "CL2"
175 A 6-bit unsigned integer constant times 2"
176 (and (match_code "const_int")
177 (match_test "!(ival & ~126)")))
179 (define_constraint "CM4"
181 A 5-bit unsigned integer constant times 4"
182 (and (match_code "const_int")
183 (match_test "!(ival & ~124)")))
185 (define_constraint "Csp"
187 A valid stack pointer offset for a short add"
188 (and (match_code "const_int")
189 (match_test "!(ival & ~124) || !(-ival & ~124)")))
191 (define_constraint "C2a"
193 Unconditional two-address add / sub constant"
194 (and (match_code "const_int")
195 (match_test "ival == (HOST_WIDE_INT) (HOST_WIDE_INT_M1U << 31)
196 || (ival >= -0x4000 && ival <= 0x4000
197 && ((ival >= 0 ? ival : -ival)
198 <= 0x7ff * (ival & -ival)))")))
200 (define_constraint "C0p"
203 (and (match_code "const_int")
204 (match_test "IS_POWEROF2_P (ival)")))
206 (define_constraint "C1p"
208 constant such that x+1 is a power of two, and x != 0"
209 (and (match_code "const_int")
210 (match_test "ival && IS_POWEROF2_P (ival + 1)")))
212 (define_constraint "C2p"
214 constant such that (~x)+1 is a power of two, and x < -1"
215 (and (match_code "const_int")
216 (match_test "TARGET_V2
218 && IS_POWEROF2_P ((~ival) + 1)")))
220 (define_constraint "C3p"
222 constant int used to select xbfu a,b,u6 instruction. The values accepted are 1 and 2."
223 (and (match_code "const_int")
224 (match_test "((ival == 1) || (ival == 2))")))
226 (define_constraint "Ccp"
228 constant such that ~x (one's Complement) is a power of two"
229 (and (match_code "const_int")
230 (match_test "IS_POWEROF2_P (~ival)")))
232 (define_constraint "Cux"
234 constant such that AND gives an unsigned extension"
235 (and (match_code "const_int")
236 (match_test "ival == 0xff || ival == 0xffff")))
238 (define_constraint "Chs"
240 constant for a highpart that can be checked with a shift (asr.f 0,rn,m)"
241 (and (match_code "const_int")
242 (match_test "IS_POWEROF2_P (-ival)")
243 (match_test "TARGET_BARREL_SHIFTER")))
245 (define_constraint "Clo"
247 constant that fits into 16 lower bits, for movl"
248 (and (match_code "const_int")
249 (match_test "TARGET_NPS_BITOPS")
250 (match_test "(ival & ~0xffffU) == 0")))
252 (define_constraint "Chi"
254 constant that fits into 16 higher bits, for movh_i"
255 (and (match_code "const_int")
256 (match_test "TARGET_NPS_BITOPS")
257 (match_test "trunc_int_for_mode (ival >> 16, HImode) << 16 == ival")))
259 (define_constraint "Cbf"
261 a mask for a bit field, for AND using movb_i"
262 (and (match_code "const_int")
263 (match_test "TARGET_NPS_BITOPS")
264 (match_test "IS_POWEROF2_OR_0_P (ival + (ival & -ival))")))
266 (define_constraint "Cbn"
268 a constant integer, valid only if TARGET_NPS_BITOPS is true"
269 (and (match_code "const_int")
270 (match_test "TARGET_NPS_BITOPS")))
272 (define_constraint "C18"
275 (and (match_code "const_int")
276 (match_test "ival == 1 || ival == 2 || ival == 4 || ival == 8")))
278 (define_constraint "Crr"
280 constant that can be loaded with ror b,u6"
281 (and (match_code "const_int")
282 (match_test "(ival & ~0x8000001f) == 0 && !arc_ccfsm_cond_exec_p ()")))
284 (define_constraint "Cbi"
286 constant that can be loaded with movbi.cl"
287 (and (match_code "const_int")
288 (match_test "TARGET_NPS_BITOPS")
290 || ((ival & 0xffffffffUL) >> exact_log2 (ival & -ival)
293 ;; Floating-point constraints
295 (define_constraint "G"
297 A 32-bit constant double value"
298 (and (match_code "const_double")
299 (match_test "arc_double_limm_p (op)")))
301 (define_constraint "H"
303 All const_double values (including 64-bit values)"
304 (and (match_code "const_double")
307 (define_constraint "CfZ"
309 Match a floating-point zero"
310 (and (match_code "const_double")
311 (match_test "op == CONST0_RTX (SFmode)")))
313 ;; Memory constraints
314 (define_memory_constraint "T"
316 A valid memory operand for ARCompact load instructions"
317 (and (match_code "mem")
318 (match_test "compact_memory_operand_p (op, mode, false, false)")))
320 (define_memory_constraint "Uts"
322 A valid memory operand for ARCompact load instructions scaled"
323 (and (match_code "mem")
324 (match_test "compact_memory_operand_p (op, mode, false, TARGET_CODE_DENSITY)")))
326 (define_memory_constraint "S"
328 A valid memory operand for ARCompact store instructions"
329 (and (match_code "mem")
330 (match_test "compact_store_memory_operand (op, VOIDmode)")))
332 (define_memory_constraint "Uex"
334 A valid memory operand for limm-free extend instructions"
335 (and (match_code "mem")
336 (match_test "!cmem_address (XEXP (op, 0), SImode)")
337 (not (match_operand 0 "long_immediate_loadstore_operand"))))
339 (define_memory_constraint "Usd"
341 A valid _small-data_ memory operand for ARCompact instructions"
342 (and (match_code "mem")
343 (match_test "compact_sda_memory_operand (op, VOIDmode, true)")))
345 ; Usc constant is only used for storing long constants, hence we can
346 ; have only [b,s9], and [b] types of addresses.
347 (define_memory_constraint "Usc"
349 A valid memory operand for storing constants"
350 (and (match_code "mem")
351 (match_test "!CONSTANT_P (XEXP (op,0))")))
353 (define_constraint "Us<"
356 (and (match_code "mem")
357 (match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")
358 (match_test "REG_P (XEXP (XEXP (op, 0), 0))")
359 (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
361 (define_constraint "Us>"
363 Stack post-increment"
364 (and (match_code "mem")
365 (match_test "GET_CODE (XEXP (op, 0)) == POST_INC")
366 (match_test "REG_P (XEXP (XEXP (op, 0), 0))")
367 (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
369 (define_constraint "Ucm"
372 (and (match_code "mem")
373 (match_test "TARGET_NPS_CMEM && cmem_address (XEXP (op, 0), VOIDmode)")))
375 ;; General constraints
377 (define_constraint "Cbr"
379 (ior (and (match_code "symbol_ref")
380 (match_test "!arc_is_longcall_p (op)"))
381 (match_code "label_ref")))
383 (define_constraint "Cbp"
384 "predicable branch/call destination"
385 (ior (and (match_code "symbol_ref")
386 (match_test "arc_is_shortcall_p (op)"))
387 (match_code "label_ref")))
389 (define_constraint "Cji"
391 (and (match_code "symbol_ref")
392 (match_test "TARGET_CODE_DENSITY")
393 (match_test "arc_is_jli_call_p (op)")))
395 (define_constraint "Csc"
397 (and (match_code "symbol_ref")
398 (match_test "TARGET_CODE_DENSITY")
399 (match_test "TARGET_EM")
400 (match_test "arc_is_secure_call_p (op)")))
402 (define_constraint "Cpc"
403 "pc-relative constant"
404 (match_test "arc_legitimate_pic_addr_p (op)"))
406 (define_constraint "Clb"
408 (and (match_code "label_ref")
409 (match_test "arc_text_label (as_a <rtx_insn *> (XEXP (op, 0)))")))
411 (define_constraint "Cal"
412 "constant for arithmetic/logical operations"
413 (match_test "immediate_operand (op, VOIDmode) && !arc_legitimate_pic_addr_p (op)"))
415 (define_constraint "C32"
416 "32 bit constant for arithmetic/logical operations"
417 (match_test "immediate_operand (op, VOIDmode)
418 && !arc_legitimate_pic_addr_p (op)
419 && !satisfies_constraint_I (op)"))
421 (define_constraint "Csz"
422 "a 32 bit constant avoided when compiling for size."
423 (match_test "immediate_operand (op, VOIDmode)
424 && !arc_legitimate_pic_addr_p (op)
425 && !(satisfies_constraint_I (op) && optimize_size)"))
427 ; Note that the 'cryptic' register constraints will not make reload use the
428 ; associated class to reload into, but this will not penalize reloading of any
429 ; other operands, or using an alternate part of the same alternative.
431 ; Rcq is different in three important ways from a register class constraint:
432 ; - It does not imply a register class, hence reload will not use it to drive
434 ; - It matches even when there is no register class to describe its accepted
435 ; set; not having such a set again lessens the impact on register allocation.
436 ; - It won't match when the instruction is conditionalized by the ccfsm.
437 (define_constraint "Rcq"
439 Cryptic q - for short insn generation while not affecting register allocation
440 Registers usable in ARCompact 16-bit instructions: @code{r0}-@code{r3},
441 @code{r12}-@code{r15}"
442 (and (match_code "reg")
443 (match_test "TARGET_Rcq
444 && !arc_ccfsm_cond_exec_p ()
445 && IN_RANGE (REGNO (op) ^ 4, 4, 11)")))
447 ; If we need a reload, we generally want to steer reload to use three-address
448 ; alternatives in preference of two-address alternatives, unless the
449 ; three-address alternative introduces a LIMM that is unnecessary for the
450 ; two-address alternative.
451 (define_constraint "Rcw"
453 Cryptic w - for use in early alternatives with matching constraint"
454 (and (match_code "reg")
457 && REGNO (op) < FIRST_PSEUDO_REGISTER
458 && TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS],
461 (define_constraint "Rcr"
463 Cryptic r - for use in early alternatives with matching constraint"
464 (and (match_code "reg")
467 && REGNO (op) < FIRST_PSEUDO_REGISTER
468 && TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS],
471 (define_constraint "Rcb"
473 Stack Pointer register @code{r28} - do not reload into its class"
474 (and (match_code "reg")
475 (match_test "REGNO (op) == 28")))
477 (define_constraint "Rck"
479 blink (usful for push_s / pop_s)"
480 (and (match_code "reg")
481 (match_test "REGNO (op) == 31")))
483 (define_constraint "Rs5"
485 sibcall register - only allow one of the five available 16 bit isnsn.
486 Registers usable in ARCompact 16-bit instructions: @code{r0}-@code{r3},
488 (and (match_code "reg")
489 (match_test "!arc_ccfsm_cond_exec_p ()")
490 (ior (match_test "(unsigned) REGNO (op) <= 3")
491 (match_test "REGNO (op) == 12"))))
493 (define_constraint "Rcc"
496 (and (match_code "reg") (match_test "cc_register (op, VOIDmode)")))
499 (define_constraint "Q"
501 Integer constant zero"
502 (and (match_code "const_int")
503 (match_test "IS_ZERO (ival)")))
505 (define_constraint "Cm1"
507 Integer signed constant in the interval [-1,6]"
508 (and (match_code "const_int")
509 (match_test "(ival >= -1) && (ival <=6)")
510 (match_test "TARGET_V2")))
512 (define_constraint "Cm2"
514 A signed 9-bit integer constant."
515 (and (match_code "const_int")
516 (match_test "(ival >= -256) && (ival <=255)")))
518 (define_constraint "Cm3"
520 A signed 6-bit integer constant."
521 (and (match_code "const_int")
522 (match_test "(ival >= -32) && (ival <=31)")
523 (match_test "TARGET_V2")))
525 (define_constraint "C62"
527 An unsigned 6-bit integer constant, up to 62."
528 (and (match_code "const_int")
529 (match_test "UNSIGNED_INT6 (ival - 1)")))
531 ;; Memory constraint used for atomic ops.
532 (define_memory_constraint "ATO"
533 "A memory with only a base register"
534 (match_operand 0 "mem_noofs_operand"))
536 (define_constraint "J12"
538 An unsigned 12-bit integer constant."
539 (and (match_code "const_int")
540 (match_test "UNSIGNED_INT12 (ival)")))
542 (define_constraint "J16"
544 An unsigned 16-bit integer constant"
545 (and (match_code "const_int")
546 (match_test "UNSIGNED_INT16 (ival)")))
548 ; Memory addresses suited for code density load ops
549 (define_memory_constraint "Ucd"
551 A valid memory operand for use with code density load ops"
552 (and (match_code "mem")
553 (match_test "compact_memory_operand_p (op, mode, true, false)")
554 (match_test "TARGET_V2")))
556 (define_register_constraint "h"
557 "TARGET_V2 ? AC16_H_REGS : NO_REGS"
558 "5-bit h register set except @code{r30} and @code{r29}:
559 @code{r0}-@code{r31}, nonfixed core register")
561 ; Code density registers
562 (define_register_constraint "Rcd"
563 "TARGET_CODE_DENSITY ? R0R3_CD_REGS : NO_REGS"
565 core register @code{r0}-@code{r3}")
567 (define_register_constraint "Rsd"
568 "TARGET_CODE_DENSITY ? R0R1_CD_REGS : NO_REGS"
570 core register @code{r0}-@code{r1}")
572 (define_register_constraint "Rzd"
573 "TARGET_CODE_DENSITY ? R0_REGS : NO_REGS"
575 @code{r0} register for code density instructions.")