1 ;; Constraint definitions for LoongArch.
2 ;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 ;; Contributed by Loongson Ltd.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;; Register constraints
24 ;; "b" "A constant call not local address."
25 ;; "c" "A constant call local address."
31 ;; "i" "Matches a general integer constant." (Global non-architectural)
33 ;; "k" "A memory operand whose address is formed by a base register and
34 ;; (optionally scaled) index register."
35 ;; "l" "A signed 16-bit constant."
36 ;; "m" "A memory operand whose address is formed by a base register and offset
37 ;; that is suitable for use in instructions with the same addressing mode
38 ;; as @code{st.w} and @code{ld.w}."
39 ;; "n" "Matches a non-symbolic integer constant." (Global non-architectural)
40 ;; "o" "Matches an offsettable memory reference." (Global non-architectural)
41 ;; "p" "Matches a general address." (Global non-architectural)
43 ;; "r" GENERAL_REGS (Global non-architectural)
44 ;; "s" "Matches a symbolic integer constant." (Global non-architectural)
46 ;; "u" "A signed 52bit constant and low 32-bit is zero (for logic instructions)"
47 ;; "v" "A signed 64-bit constant and low 44-bit is zero (for logic instructions)."
48 ;; "w" "Matches any valid memory."
56 ;; "E" "Matches a floating-point constant." (Global non-architectural)
57 ;; "F" "Matches a floating-point constant." (Global non-architectural)
58 ;; "G" "Floating-point zero."
60 ;; "I" "A signed 12-bit constant (for arithmetic instructions)."
61 ;; "J" "Integer zero."
62 ;; "K" "An unsigned 12-bit constant (for logic instructions)."
65 ;; "A signed constant in [-4096, 2048) or (2047, 4094]."
67 ;; "A signed 32-bit constant and low 16-bit is zero, which can be
68 ;; added onto a register with addu16i.d. It matches nothing if
69 ;; the addu16i.d instruction is not available."
71 ;; "A signed 64-bit constant can be expressed as Lb + I, but not a
74 ;; "A signed 64-bit constant can be expressed as Lb + Lb, but not a
77 ;; "A signed 32-bit constant can be expressed as Lb + I, but not a
79 ;; "M" "A constant that cannot be loaded using @code{lui}, @code{addiu}
81 ;; "N" "A constant in the range -65535 to -1 (inclusive)."
82 ;; "O" "A signed 15-bit constant."
83 ;; "P" "A constant in the range 1 to 65535 (inclusive)."
85 ;; "R" "An address that can be used in a non-macro load or store."
89 ;; "V" "Matches a non-offsettable memory reference." (Global non-architectural)
91 ;; "X" "Matches anything." (Global non-architectural)
94 ;; "A constant @code{move_operand} that can be safely loaded using
100 ;; "A memory operand whose address is formed by a base register and offset
101 ;; that is suitable for use in instructions with the same addressing mode
102 ;; as @code{ll.w} and @code{sc.w}."
104 ;; "An address that is held in a general-purpose register.
105 ;; The offset is zero"
107 ;; "An address operand whose address is formed by a base register
108 ;; and offset that is suitable for use in instructions with the same
109 ;; addressing mode as @code{preld}."
110 ;; "<" "Matches a pre-dec or post-dec operand." (Global non-architectural)
111 ;; ">" "Matches a pre-inc or post-inc operand." (Global non-architectural)
113 (define_constraint "b"
115 A constant call no local address."
116 (match_operand 0 "is_const_call_no_local_symbol"))
118 (define_constraint "c"
120 A constant call local address."
121 (match_operand 0 "is_const_call_local_symbol"))
123 (define_register_constraint "e" "JIRL_REGS"
126 (define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS : NO_REGS"
127 "A floating-point register (if available).")
129 (define_register_constraint "j" "SIBCALL_REGS"
132 (define_memory_constraint "k"
133 "A memory operand whose address is formed by a base register and (optionally scaled)
135 (and (match_code "mem")
136 (match_test "loongarch_base_index_address_p (XEXP (op, 0), mode)")))
138 (define_constraint "l"
139 "A signed 16-bit constant."
140 (and (match_code "const_int")
141 (match_test "IMM16_OPERAND (ival)")))
143 (define_memory_constraint "m"
144 "A memory operand whose address is formed by a base register and offset
145 that is suitable for use in instructions with the same addressing mode
146 as @code{st.w} and @code{ld.w}."
147 (and (match_code "mem")
148 (match_test "loongarch_12bit_offset_address_p (XEXP (op, 0), mode)")))
150 (define_register_constraint "q" "CSR_REGS"
151 "A general-purpose register except for $r0 and $r1 for lcsr.")
153 (define_constraint "u"
154 "A signed 52bit constant and low 32-bit is zero (for logic instructions)."
155 (and (match_code "const_int")
156 (match_test "LU32I_OPERAND (ival)")))
158 (define_constraint "v"
159 "A signed 64-bit constant and low 44-bit is zero (for logic instructions)."
160 (and (match_code "const_int")
161 (match_test "LU52I_OPERAND (ival)")))
163 (define_register_constraint "z" "FCC_REGS"
164 "A floating-point condition code register.")
166 ;; Floating-point constraints
168 (define_constraint "G"
169 "Floating-point zero."
170 (and (match_code "const_double")
171 (match_test "op == CONST0_RTX (mode)")))
173 ;; Integer constraints
175 (define_constraint "I"
176 "A signed 12-bit constant (for arithmetic instructions)."
177 (and (match_code "const_int")
178 (match_test "IMM12_OPERAND (ival)")))
180 (define_constraint "J"
182 (and (match_code "const_int")
183 (match_test "ival == 0")))
185 (define_constraint "K"
186 "An unsigned 12-bit constant (for logic instructions)."
187 (and (match_code "const_int")
188 (match_test "IMM12_OPERAND_UNSIGNED (ival)")))
190 (define_constraint "La"
191 "A signed constant in [-4096, 2048) or (2047, 4094]."
192 (and (match_code "const_int")
193 (match_test "DUAL_IMM12_OPERAND (ival)")))
195 (define_constraint "Lb"
196 "A signed 32-bit constant and low 16-bit is zero, which can be added
197 onto a register with addu16i.d."
198 (and (match_code "const_int")
199 (match_test "ADDU16I_OPERAND (ival)")))
201 (define_constraint "Lc"
202 "A signed 64-bit constant can be expressed as Lb + I, but not a single Lb
204 (and (match_code "const_int")
205 (match_test "loongarch_addu16i_imm12_operand_p (ival, DImode)")))
207 (define_constraint "Ld"
208 "A signed 64-bit constant can be expressed as Lb + Lb, but not a single
210 (and (match_code "const_int")
211 (match_test "DUAL_ADDU16I_OPERAND (ival)")))
213 (define_constraint "Le"
214 "A signed 32-bit constant can be expressed as Lb + I, but not a single Lb
216 (and (match_code "const_int")
217 (match_test "loongarch_addu16i_imm12_operand_p (ival, SImode)")))
219 (define_constraint "M"
220 "A constant that cannot be loaded using @code{lui}, @code{addiu}
222 (and (match_code "const_int")
223 (not (match_test "IMM12_OPERAND (ival)"))
224 (not (match_test "IMM12_OPERAND_UNSIGNED (ival)"))
225 (not (match_test "LU12I_OPERAND (ival)"))))
227 (define_constraint "N"
228 "A constant in the range -65535 to -1 (inclusive)."
229 (and (match_code "const_int")
230 (match_test "ival >= -0xffff && ival < 0")))
232 (define_constraint "O"
233 "A signed 15-bit constant."
234 (and (match_code "const_int")
235 (match_test "ival >= -0x4000 && ival < 0x4000")))
237 (define_constraint "P"
238 "A constant in the range 1 to 65535 (inclusive)."
239 (and (match_code "const_int")
240 (match_test "ival > 0 && ival < 0x10000")))
242 ;; General constraints
244 (define_memory_constraint "R"
245 "An address that can be used in a non-macro load or store."
246 (and (match_code "mem")
247 (match_test "loongarch_address_insns (XEXP (op, 0), mode, false) == 1")))
248 (define_constraint "S"
250 A constant call address."
251 (and (match_operand 0 "call_insn_operand")
252 (match_test "CONSTANT_P (op)")))
254 (define_constraint "YG"
257 (and (match_code "const_vector")
258 (match_test "op == CONST0_RTX (mode)")))
260 (define_constraint "YA"
262 An unsigned 6-bit constant."
263 (and (match_code "const_int")
264 (match_test "UIMM6_OPERAND (ival)")))
266 (define_constraint "YB"
268 A signed 10-bit constant."
269 (and (match_code "const_int")
270 (match_test "IMM10_OPERAND (ival)")))
272 (define_constraint "Yb"
274 (match_operand 0 "qi_mask_operand"))
276 (define_constraint "Yd"
278 A constant @code{move_operand} that can be safely loaded using
280 (and (match_operand 0 "move_operand")
281 (match_test "CONSTANT_P (op)")))
283 (define_constraint "Yh"
285 (match_operand 0 "hi_mask_operand"))
287 (define_constraint "Yw"
289 (match_operand 0 "si_mask_operand"))
291 (define_constraint "Yx"
293 (match_operand 0 "low_bitmask_operand"))
295 (define_constraint "YI"
297 A replicated vector const in which the replicated value is in the range
299 (and (match_code "const_vector")
300 (match_test "loongarch_const_vector_same_int_p (op, mode, -512, 511)")))
302 (define_constraint "YC"
304 A replicated vector const in which the replicated value has a single
306 (and (match_code "const_vector")
307 (match_test "loongarch_const_vector_bitimm_set_p (op, mode)")))
309 (define_constraint "YZ"
311 A replicated vector const in which the replicated value has a single
313 (and (match_code "const_vector")
314 (match_test "loongarch_const_vector_bitimm_clr_p (op, mode)")))
316 (define_constraint "Unv5"
318 A replicated vector const in which the replicated value is in the range
320 (and (match_code "const_vector")
321 (match_test "loongarch_const_vector_same_int_p (op, mode, -31, 0)")))
323 (define_constraint "Uuv5"
325 A replicated vector const in which the replicated value is in the range
327 (and (match_code "const_vector")
328 (match_test "loongarch_const_vector_same_int_p (op, mode, 0, 31)")))
330 (define_constraint "Usv5"
332 A replicated vector const in which the replicated value is in the range
334 (and (match_code "const_vector")
335 (match_test "loongarch_const_vector_same_int_p (op, mode, -16, 15)")))
337 (define_constraint "Uuv6"
339 A replicated vector const in which the replicated value is in the range
341 (and (match_code "const_vector")
342 (match_test "loongarch_const_vector_same_int_p (op, mode, 0, 63)")))
344 (define_constraint "Urv8"
346 A replicated vector const with replicated byte values as well as elements"
347 (and (match_code "const_vector")
348 (match_test "loongarch_const_vector_same_bytes_p (op, mode)")))
350 (define_memory_constraint "ZC"
351 "A memory operand whose address is formed by a base register and offset
352 that is suitable for use in instructions with the same addressing mode
353 as @code{ll.w} and @code{sc.w}."
354 (and (match_code "mem")
355 (match_test "loongarch_14bit_shifted_offset_address_p (XEXP (op, 0), mode)")))
357 (define_memory_constraint "ZB"
359 An address that is held in a general-purpose register.
361 (and (match_code "mem")
362 (match_test "REG_P (XEXP (op, 0))")))
364 (define_address_constraint "ZD"
365 "An address operand whose address is formed by a base register
366 and offset that is suitable for use in instructions with the same
367 addressing mode as @code{preld}."
368 (match_test "loongarch_12bit_offset_address_p (op, mode)"))