]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/arc/constraints.md
[PATCH] [ARC] Add support for naked functions.
[thirdparty/gcc.git] / gcc / config / arc / constraints.md
CommitLineData
526b7aee 1;; Constraint definitions for Synopsys DesignWare ARC.
cbe34bb5 2;; Copyright (C) 2007-2017 Free Software Foundation, Inc.
526b7aee
SV
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; Most instructions accept arbitrary core registers for their inputs, even
23; if the core register in question cannot be written to, like the multiply
fb155425 24; result registers of ARC600.
526b7aee
SV
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" "CHEAP_CORE_REGS"
28 "core register @code{r0}-@code{r31}, @code{ap},@code{pcl}")
29
30; All core regs - e.g. for when we must have a way to reload a register.
31(define_register_constraint "Rac" "ALL_CORE_REGS"
32 "core register @code{r0}-@code{r60}, @code{ap},@code{pcl}")
33
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" "WRITABLE_CORE_REGS"
40 "writable core register: @code{r0}-@code{r31}, @code{r60}, nonfixed core register")
41
42(define_register_constraint "W" "MPY_WRITABLE_CORE_REGS"
43 "writable core register except @code{LP_COUNT} (@code{r60}): @code{r0}-@code{r31}, nonfixed core register")
44
45(define_register_constraint "l" "LPCOUNT_REG"
46 "@internal
47 Loop count register @code{r60}")
48
49(define_register_constraint "x" "R0_REGS"
50 "@code{R0} register.")
51
52(define_register_constraint "Rgp" "GP_REG"
53 "@internal
54 Global Pointer register @code{r26}")
55
56(define_register_constraint "f" "FP_REG"
57 "@internal
58 Frame Pointer register @code{r27}")
59
60(define_register_constraint "b" "SP_REGS"
61 "@internal
62 Stack Pointer register @code{r28}")
63
64(define_register_constraint "k" "LINK_REGS"
65 "@internal
66 Link Registers @code{ilink1}:@code{r29}, @code{ilink2}:@code{r30},
67 @code{blink}:@code{r31},")
68
ceaaa9fe 69(define_register_constraint "q" "TARGET_Q_CLASS ? ARCOMPACT16_REGS : NO_REGS"
526b7aee
SV
70 "Registers usable in ARCompact 16-bit instructions: @code{r0}-@code{r3},
71 @code{r12}-@code{r15}")
72
ceaaa9fe
JR
73; NPS400 bitfield instructions require registers from the r0-r3,r12-r15
74; range, and thus we need a register class and constraint that works
75; independently of size optimization.
76(define_register_constraint
77 "Rrq" "TARGET_RRQ_CLASS ? ARCOMPACT16_REGS : NO_REGS"
78 "Registers usable in NPS400 bitfield instructions: @code{r0}-@code{r3},
79 @code{r12}-@code{r15}")
80
526b7aee
SV
81(define_register_constraint "e" "AC16_BASE_REGS"
82 "Registers usable as base-regs of memory addresses in ARCompact 16-bit memory
83 instructions: @code{r0}-@code{r3}, @code{r12}-@code{r15}, @code{sp}")
84
85(define_register_constraint "D" "DOUBLE_REGS"
86 "ARC FPX (dpfp) 64-bit registers. @code{D0}, @code{D1}")
87
88(define_register_constraint "d" "SIMD_DMA_CONFIG_REGS"
89 "@internal
90 ARC SIMD DMA configuration registers @code{di0}-@code{di7},
91 @code{do0}-@code{do7}")
92
93(define_register_constraint "v" "SIMD_VR_REGS"
94 "ARC SIMD 128-bit registers @code{VR0}-@code{VR23}")
95
96; We could allow call-saved registers for sibling calls if we restored them
97; in the delay slot of the call. However, that would not allow to adjust the
98; stack pointer afterwards, so the call-saved register would have to be
99; restored from a call-used register that was just loaded with the value
100; before. So sticking to call-used registers for sibcalls will likely
101; generate better code overall.
102(define_register_constraint "Rsc" "SIBCALL_REGS"
103 "@internal
104 Sibling call register")
105
106;; Integer constraints
107
108(define_constraint "I"
109 "@internal
110 A signed 12-bit integer constant."
111 (and (match_code "const_int")
112 (match_test "SIGNED_INT12 (ival)")))
113
114(define_constraint "K"
115 "@internal
116 A 3-bit unsigned integer constant"
117 (and (match_code "const_int")
118 (match_test "UNSIGNED_INT3 (ival)")))
119
120(define_constraint "L"
121 "@internal
122 A 6-bit unsigned integer constant"
123 (and (match_code "const_int")
124 (match_test "UNSIGNED_INT6 (ival)")))
125
126(define_constraint "CnL"
127 "@internal
128 One's complement of a 6-bit unsigned integer constant"
129 (and (match_code "const_int")
130 (match_test "UNSIGNED_INT6 (~ival)")))
131
132(define_constraint "CmL"
133 "@internal
134 Two's complement of a 6-bit unsigned integer constant"
135 (and (match_code "const_int")
136 (match_test "UNSIGNED_INT6 (-ival)")))
137
f50bb868
CZ
138(define_constraint "C16"
139 "@internal
140 A 16-bit signed integer constant"
141 (and (match_code "const_int")
142 (match_test "SIGNED_INT16 (ival)")))
143
526b7aee
SV
144(define_constraint "M"
145 "@internal
146 A 5-bit unsigned integer constant"
147 (and (match_code "const_int")
148 (match_test "UNSIGNED_INT5 (ival)")))
149
150(define_constraint "N"
151 "@internal
152 Integer constant 1"
153 (and (match_code "const_int")
154 (match_test "IS_ONE (ival)")))
155
156(define_constraint "O"
157 "@internal
158 A 7-bit unsigned integer constant"
159 (and (match_code "const_int")
160 (match_test "UNSIGNED_INT7 (ival)")))
161
162(define_constraint "P"
163 "@internal
164 An 8-bit unsigned integer constant"
165 (and (match_code "const_int")
166 (match_test "UNSIGNED_INT8 (ival)")))
167
168(define_constraint "C_0"
169 "@internal
170 Zero"
171 (and (match_code "const_int")
172 (match_test "ival == 0")))
173
174(define_constraint "Cn0"
175 "@internal
176 Negative or zero"
177 (and (match_code "const_int")
178 (match_test "ival <= 0")))
179
180(define_constraint "Cca"
181 "@internal
182 Conditional or three-address add / sub constant"
183 (and (match_code "const_int")
c419f71c 184 (match_test "ival == (HOST_WIDE_INT)(HOST_WIDE_INT_M1U << 31)
526b7aee
SV
185 || (ival >= -0x1f8 && ival <= 0x1f8
186 && ((ival >= 0 ? ival : -ival)
187 <= 0x3f * (ival & -ival)))")))
188
189; intersection of "O" and "Cca".
190(define_constraint "CL2"
191 "@internal
192 A 6-bit unsigned integer constant times 2"
193 (and (match_code "const_int")
194 (match_test "!(ival & ~126)")))
195
196(define_constraint "CM4"
197 "@internal
198 A 5-bit unsigned integer constant times 4"
199 (and (match_code "const_int")
200 (match_test "!(ival & ~124)")))
201
202(define_constraint "Csp"
203 "@internal
204 A valid stack pointer offset for a short add"
205 (and (match_code "const_int")
206 (match_test "!(ival & ~124) || !(-ival & ~124)")))
207
208(define_constraint "C2a"
209 "@internal
210 Unconditional two-address add / sub constant"
211 (and (match_code "const_int")
4e671509 212 (match_test "ival == (HOST_WIDE_INT) (HOST_WIDE_INT_M1U << 31)
526b7aee
SV
213 || (ival >= -0x4000 && ival <= 0x4000
214 && ((ival >= 0 ? ival : -ival)
215 <= 0x7ff * (ival & -ival)))")))
216
217(define_constraint "C0p"
218 "@internal
219 power of two"
220 (and (match_code "const_int")
221 (match_test "IS_POWEROF2_P (ival)")))
222
223(define_constraint "C1p"
224 "@internal
225 constant such that x+1 is a power of two, and x != 0"
226 (and (match_code "const_int")
227 (match_test "ival && IS_POWEROF2_P (ival + 1)")))
228
fc1c2d04
CZ
229(define_constraint "C2p"
230 "@internal
231 constant such that (~x)+1 is a power of two, and x < -1"
232 (and (match_code "const_int")
233 (match_test "TARGET_V2
234 && (ival < -1)
235 && IS_POWEROF2_P ((~ival) + 1)")))
236
f50bb868
CZ
237(define_constraint "C3p"
238 "@internal
239 constant int used to select xbfu a,b,u6 instruction. The values accepted are 1 and 2."
240 (and (match_code "const_int")
241 (match_test "((ival == 1) || (ival == 2))")))
242
526b7aee
SV
243(define_constraint "Ccp"
244 "@internal
245 constant such that ~x (one's Complement) is a power of two"
246 (and (match_code "const_int")
247 (match_test "IS_POWEROF2_P (~ival)")))
248
249(define_constraint "Cux"
250 "@internal
251 constant such that AND gives an unsigned extension"
252 (and (match_code "const_int")
253 (match_test "ival == 0xff || ival == 0xffff")))
254
ceaaa9fe
JR
255(define_constraint "Chs"
256 "@internal
257 constant for a highpart that can be checked with a shift (asr.f 0,rn,m)"
258 (and (match_code "const_int")
491483b0
CZ
259 (match_test "IS_POWEROF2_P (-ival)")
260 (match_test "TARGET_BARREL_SHIFTER")))
ceaaa9fe
JR
261
262(define_constraint "Clo"
263 "@internal
264 constant that fits into 16 lower bits, for movl"
265 (and (match_code "const_int")
266 (match_test "TARGET_NPS_BITOPS")
267 (match_test "(ival & ~0xffffU) == 0")))
268
269(define_constraint "Chi"
270 "@internal
271 constant that fits into 16 higher bits, for movh_i"
272 (and (match_code "const_int")
273 (match_test "TARGET_NPS_BITOPS")
274 (match_test "trunc_int_for_mode (ival >> 16, HImode) << 16 == ival")))
275
276(define_constraint "Cbf"
277 "@internal
278 a mask for a bit field, for AND using movb_i"
279 (and (match_code "const_int")
280 (match_test "TARGET_NPS_BITOPS")
281 (match_test "IS_POWEROF2_OR_0_P (ival + (ival & -ival))")))
282
283(define_constraint "Cbn"
284 "@internal
285 a constant integer, valid only if TARGET_NPS_BITOPS is true"
286 (and (match_code "const_int")
287 (match_test "TARGET_NPS_BITOPS")))
288
289(define_constraint "C18"
290 "@internal
291 1,2,4 or 8"
292 (and (match_code "const_int")
293 (match_test "ival == 1 || ival == 2 || ival == 4 || ival == 8")))
294
526b7aee
SV
295(define_constraint "Crr"
296 "@internal
297 constant that can be loaded with ror b,u6"
298 (and (match_code "const_int")
299 (match_test "(ival & ~0x8000001f) == 0 && !arc_ccfsm_cond_exec_p ()")))
300
ceaaa9fe
JR
301(define_constraint "Cbi"
302 "@internal
303 constant that can be loaded with movbi.cl"
304 (and (match_code "const_int")
305 (match_test "TARGET_NPS_BITOPS")
306 (match_test "!ival
307 || ((ival & 0xffffffffUL) >> exact_log2 (ival & -ival)
308 <= 0xff)")))
309
526b7aee
SV
310;; Floating-point constraints
311
312(define_constraint "G"
313 "@internal
314 A 32-bit constant double value"
315 (and (match_code "const_double")
316 (match_test "arc_double_limm_p (op)")))
317
318(define_constraint "H"
319 "@internal
320 All const_double values (including 64-bit values)"
321 (and (match_code "const_double")
322 (match_test "1")))
323
324;; Memory constraints
325(define_memory_constraint "T"
326 "@internal
327 A valid memory operand for ARCompact load instructions"
328 (and (match_code "mem")
fc1c2d04
CZ
329 (match_test "compact_memory_operand_p (op, mode, false, false)")))
330
331(define_memory_constraint "Uts"
332 "@internal
333 A valid memory operand for ARCompact load instructions scaled"
334 (and (match_code "mem")
335 (match_test "compact_memory_operand_p (op, mode, false, TARGET_CODE_DENSITY)")))
526b7aee
SV
336
337(define_memory_constraint "S"
338 "@internal
339 A valid memory operand for ARCompact store instructions"
340 (and (match_code "mem")
341 (match_test "compact_store_memory_operand (op, VOIDmode)")))
342
4d03dc2f
JR
343(define_memory_constraint "Uex"
344 "@internal
345 A valid memory operand for limm-free extend instructions"
346 (and (match_code "mem")
347 (match_test "!cmem_address (XEXP (op, 0), SImode)")
348 (not (match_operand 0 "long_immediate_loadstore_operand"))))
349
c20ef9d2
AB
350; Don't use define_memory_constraint here as the relocation patching
351; for small data symbols only works within a ld/st instruction and
352; define_memory_constraint may result in the address being calculated
353; into a register first.
354(define_constraint "Usd"
355 "@internal
356 A valid _small-data_ memory operand for ARCompact instructions"
357 (and (match_code "mem")
fc1c2d04 358 (match_test "compact_sda_memory_operand (op, VOIDmode)")))
526b7aee
SV
359
360(define_memory_constraint "Usc"
361 "@internal
362 A valid memory operand for storing constants"
363 (and (match_code "mem")
364 (match_test "!CONSTANT_P (XEXP (op,0))")
365;; ??? the assembler rejects stores of immediates to small data.
366 (match_test "!compact_sda_memory_operand (op, VOIDmode)")))
367
c20ef9d2 368(define_constraint "Us<"
526b7aee
SV
369 "@internal
370 Stack pre-decrement"
371 (and (match_code "mem")
372 (match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")
373 (match_test "REG_P (XEXP (XEXP (op, 0), 0))")
374 (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
375
c20ef9d2 376(define_constraint "Us>"
526b7aee
SV
377 "@internal
378 Stack post-increment"
379 (and (match_code "mem")
380 (match_test "GET_CODE (XEXP (op, 0)) == POST_INC")
381 (match_test "REG_P (XEXP (XEXP (op, 0), 0))")
382 (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
383
4d03dc2f
JR
384(define_constraint "Ucm"
385 "@internal
386 cmem access"
387 (and (match_code "mem")
388 (match_test "TARGET_NPS_CMEM && cmem_address (XEXP (op, 0), VOIDmode)")))
389
526b7aee
SV
390;; General constraints
391
392(define_constraint "Cbr"
393 "Branch destination"
394 (ior (and (match_code "symbol_ref")
395 (match_test "!arc_is_longcall_p (op)"))
396 (match_code "label_ref")))
397
398(define_constraint "Cbp"
399 "predicable branch/call destination"
400 (ior (and (match_code "symbol_ref")
401 (match_test "arc_is_shortcall_p (op)"))
402 (match_code "label_ref")))
403
404(define_constraint "Cpc"
405 "pc-relative constant"
406 (match_test "arc_legitimate_pc_offset_p (op)"))
407
408(define_constraint "Clb"
409 "label"
410 (and (match_code "label_ref")
b32d5189 411 (match_test "arc_text_label (as_a <rtx_insn *> (XEXP (op, 0)))")))
526b7aee
SV
412
413(define_constraint "Cal"
414 "constant for arithmetic/logical operations"
415 (match_test "immediate_operand (op, VOIDmode) && !arc_legitimate_pc_offset_p (op)"))
416
417(define_constraint "C32"
418 "32 bit constant for arithmetic/logical operations"
419 (match_test "immediate_operand (op, VOIDmode)
420 && !arc_legitimate_pc_offset_p (op)
421 && !satisfies_constraint_I (op)"))
422
423; Note that the 'cryptic' register constraints will not make reload use the
424; associated class to reload into, but this will not penalize reloading of any
425; other operands, or using an alternate part of the same alternative.
426
427; Rcq is different in three important ways from a register class constraint:
428; - It does not imply a register class, hence reload will not use it to drive
429; reloads.
430; - It matches even when there is no register class to describe its accepted
431; set; not having such a set again lessens the impact on register allocation.
432; - It won't match when the instruction is conditionalized by the ccfsm.
433(define_constraint "Rcq"
434 "@internal
435 Cryptic q - for short insn generation while not affecting register allocation
436 Registers usable in ARCompact 16-bit instructions: @code{r0}-@code{r3},
437 @code{r12}-@code{r15}"
8da140e0 438 (and (match_code "reg")
526b7aee
SV
439 (match_test "TARGET_Rcq
440 && !arc_ccfsm_cond_exec_p ()
036def0f 441 && IN_RANGE (REGNO (op) ^ 4, 4, 11)")))
526b7aee
SV
442
443; If we need a reload, we generally want to steer reload to use three-address
444; alternatives in preference of two-address alternatives, unless the
445; three-address alternative introduces a LIMM that is unnecessary for the
446; two-address alternative.
447(define_constraint "Rcw"
448 "@internal
449 Cryptic w - for use in early alternatives with matching constraint"
8da140e0 450 (and (match_code "reg")
526b7aee
SV
451 (match_test
452 "TARGET_Rcw
453 && REGNO (op) < FIRST_PSEUDO_REGISTER
454 && TEST_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS],
455 REGNO (op))")))
456
457(define_constraint "Rcr"
458 "@internal
459 Cryptic r - for use in early alternatives with matching constraint"
8da140e0 460 (and (match_code "reg")
526b7aee
SV
461 (match_test
462 "TARGET_Rcw
463 && REGNO (op) < FIRST_PSEUDO_REGISTER
464 && TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS],
465 REGNO (op))")))
466
467(define_constraint "Rcb"
468 "@internal
469 Stack Pointer register @code{r28} - do not reload into its class"
8da140e0 470 (and (match_code "reg")
526b7aee
SV
471 (match_test "REGNO (op) == 28")))
472
473(define_constraint "Rck"
474 "@internal
475 blink (usful for push_s / pop_s)"
8da140e0 476 (and (match_code "reg")
526b7aee
SV
477 (match_test "REGNO (op) == 31")))
478
479(define_constraint "Rs5"
480 "@internal
481 sibcall register - only allow one of the five available 16 bit isnsn.
482 Registers usable in ARCompact 16-bit instructions: @code{r0}-@code{r3},
483 @code{r12}"
8da140e0 484 (and (match_code "reg")
526b7aee
SV
485 (match_test "!arc_ccfsm_cond_exec_p ()")
486 (ior (match_test "(unsigned) REGNO (op) <= 3")
487 (match_test "REGNO (op) == 12"))))
488
489(define_constraint "Rcc"
490 "@internal
491 Condition Codes"
8da140e0 492 (and (match_code "reg") (match_test "cc_register (op, VOIDmode)")))
526b7aee
SV
493
494
495(define_constraint "Q"
496 "@internal
497 Integer constant zero"
498 (and (match_code "const_int")
499 (match_test "IS_ZERO (ival)")))
f50bb868 500
fc1c2d04
CZ
501(define_constraint "Cm1"
502 "@internal
503 Integer signed constant in the interval [-1,6]"
504 (and (match_code "const_int")
505 (match_test "(ival >= -1) && (ival <=6)")
506 (match_test "TARGET_V2")))
507
f50bb868
CZ
508(define_constraint "Cm2"
509 "@internal
510 A signed 9-bit integer constant."
511 (and (match_code "const_int")
512 (match_test "(ival >= -256) && (ival <=255)")))
513
fc1c2d04
CZ
514(define_constraint "Cm3"
515 "@internal
516 A signed 6-bit integer constant."
517 (and (match_code "const_int")
518 (match_test "(ival >= -32) && (ival <=31)")
519 (match_test "TARGET_V2")))
520
f50bb868
CZ
521(define_constraint "C62"
522 "@internal
523 An unsigned 6-bit integer constant, up to 62."
524 (and (match_code "const_int")
525 (match_test "UNSIGNED_INT6 (ival - 1)")))
b8a64b7f
CZ
526
527;; Memory constraint used for atomic ops.
528(define_memory_constraint "ATO"
529 "A memory with only a base register"
530 (match_operand 0 "mem_noofs_operand"))
7132ae19
CZ
531
532(define_constraint "J12"
533 "@internal
534 An unsigned 12-bit integer constant."
535 (and (match_code "const_int")
536 (match_test "UNSIGNED_INT12 (ival)")))
537
538(define_constraint "J16"
539 "@internal
540 An unsigned 16-bit integer constant"
541 (and (match_code "const_int")
542 (match_test "UNSIGNED_INT16 (ival)")))
fc1c2d04
CZ
543
544; Memory addresses suited for code density load ops
545(define_memory_constraint "Ucd"
546 "@internal
547 A valid memory operand for use with code density load ops"
548 (and (match_code "mem")
549 (match_test "compact_memory_operand_p (op, mode, true, false)")
550 (match_test "TARGET_V2")))
551
552(define_register_constraint "h"
553 "TARGET_V2 ? AC16_H_REGS : NO_REGS"
554 "5-bit h register set except @code{r30} and @code{r29}:
555 @code{r0}-@code{r31}, nonfixed core register")
556
557; Code density registers
558(define_register_constraint "Rcd"
559 "TARGET_CODE_DENSITY ? R0R3_CD_REGS : NO_REGS"
560 "@internal
561 core register @code{r0}-@code{r3}")
562
563(define_register_constraint "Rsd"
564 "TARGET_CODE_DENSITY ? R0R1_CD_REGS : NO_REGS"
565 "@internal
566 core register @code{r0}-@code{r1}")
567
568(define_register_constraint "Rzd"
569 "TARGET_CODE_DENSITY ? R0_REGS : NO_REGS"
570 "@internal
571 @code{r0} register for code density instructions.")