1 ;; Constraint definitions for LoongArch.
2 ;; Copyright (C)
2021-
2023 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
99 ;; "A memory operand whose address is formed by a base register and offset
100 ;; that is suitable for use in instructions with the same addressing mode
101 ;; as @code{ll.w} and @code{sc.w}."
103 ;; "An address that is held in a general-purpose register.
104 ;; The offset is zero"
106 ;; "An address operand whose address is formed by a base register
107 ;; and offset that is suitable for use in instructions with the same
108 ;; addressing mode as @code{preld}."
109 ;; "<" "Matches a pre-dec or post-dec operand." (Global non-architectural)
110 ;; ">" "Matches a pre-inc or post-inc operand." (Global non-architectural)
112 (define_constraint "b"
114 A constant call no local address."
115 (match_operand
0 "is_const_call_no_local_symbol"))
117 (define_constraint "c"
119 A constant call local address."
120 (match_operand
0 "is_const_call_local_symbol"))
122 (define_register_constraint "e" "JIRL_REGS"
125 (define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS : NO_REGS"
126 "A floating-point register (if available).")
128 (define_register_constraint "j" "SIBCALL_REGS"
131 (define_memory_constraint "k"
132 "A memory operand whose address is formed by a base register and (optionally scaled)
134 (and (match_code "mem")
135 (match_test "loongarch_base_index_address_p (XEXP (op,
0), mode)")))
137 (define_constraint "l"
138 "A signed
16-bit constant."
139 (and (match_code "const_int")
140 (match_test "IMM16_OPERAND (ival)")))
142 (define_memory_constraint "m"
143 "A memory operand whose address is formed by a base register and offset
144 that is suitable for use in instructions with the same addressing mode
145 as @code{st.w} and @code{ld.w}."
146 (and (match_code "mem")
147 (match_test "loongarch_12bit_offset_address_p (XEXP (op,
0), mode)")))
149 (define_register_constraint "q" "CSR_REGS"
150 "A general-purpose register except for $r0 and $r1 for lcsr.")
152 (define_constraint "u"
153 "A signed
52bit constant and low
32-bit is zero (for logic instructions)."
154 (and (match_code "const_int")
155 (match_test "LU32I_OPERAND (ival)")))
157 (define_constraint "v"
158 "A signed
64-bit constant and low
44-bit is zero (for logic instructions)."
159 (and (match_code "const_int")
160 (match_test "LU52I_OPERAND (ival)")))
162 (define_register_constraint "z" "FCC_REGS"
163 "A floating-point condition code register.")
165 ;; Floating-point constraints
167 (define_constraint "G"
168 "Floating-point zero."
169 (and (match_code "const_double")
170 (match_test "op == CONST0_RTX (mode)")))
172 ;; Integer constraints
174 (define_constraint "I"
175 "A signed
12-bit constant (for arithmetic instructions)."
176 (and (match_code "const_int")
177 (match_test "IMM12_OPERAND (ival)")))
179 (define_constraint "J"
181 (and (match_code "const_int")
182 (match_test "ival ==
0")))
184 (define_constraint "K"
185 "An unsigned
12-bit constant (for logic instructions)."
186 (and (match_code "const_int")
187 (match_test "IMM12_OPERAND_UNSIGNED (ival)")))
189 (define_constraint "La"
190 "A signed constant in [-
4096,
2048) or (
2047,
4094]."
191 (and (match_code "const_int")
192 (match_test "DUAL_IMM12_OPERAND (ival)")))
194 (define_constraint "Lb"
195 "A signed
32-bit constant and low
16-bit is zero, which can be added
196 onto a register with addu16i.d."
197 (and (match_code "const_int")
198 (match_test "ADDU16I_OPERAND (ival)")))
200 (define_constraint "Lc"
201 "A signed
64-bit constant can be expressed as Lb + I, but not a single Lb
203 (and (match_code "const_int")
204 (match_test "loongarch_addu16i_imm12_operand_p (ival, DImode)")))
206 (define_constraint "Ld"
207 "A signed
64-bit constant can be expressed as Lb + Lb, but not a single
209 (and (match_code "const_int")
210 (match_test "DUAL_ADDU16I_OPERAND (ival)")))
212 (define_constraint "Le"
213 "A signed
32-bit constant can be expressed as Lb + I, but not a single Lb
215 (and (match_code "const_int")
216 (match_test "loongarch_addu16i_imm12_operand_p (ival, SImode)")))
218 (define_constraint "M"
219 "A constant that cannot be loaded using @code{lui}, @code{addiu}
221 (and (match_code "const_int")
222 (not (match_test "IMM12_OPERAND (ival)"))
223 (not (match_test "IMM12_OPERAND_UNSIGNED (ival)"))
224 (not (match_test "LU12I_OPERAND (ival)"))))
226 (define_constraint "N"
227 "A constant in the range -
65535 to -
1 (inclusive)."
228 (and (match_code "const_int")
229 (match_test "ival >= -
0xffff && ival <
0")))
231 (define_constraint "O"
232 "A signed
15-bit constant."
233 (and (match_code "const_int")
234 (match_test "ival >= -
0x4000 && ival <
0x4000")))
236 (define_constraint "P"
237 "A constant in the range
1 to
65535 (inclusive)."
238 (and (match_code "const_int")
239 (match_test "ival >
0 && ival <
0x10000")))
241 ;; General constraints
243 (define_memory_constraint "R"
244 "An address that can be used in a non-macro load or store."
245 (and (match_code "mem")
246 (match_test "loongarch_address_insns (XEXP (op,
0), mode, false) ==
1")))
247 (define_constraint "S"
249 A constant call address."
250 (and (match_operand
0 "call_insn_operand")
251 (match_test "CONSTANT_P (op)")))
253 (define_constraint "YG"
256 (and (match_code "const_vector")
257 (match_test "op == CONST0_RTX (mode)")))
259 (define_constraint "YA"
261 An unsigned
6-bit constant."
262 (and (match_code "const_int")
263 (match_test "UIMM6_OPERAND (ival)")))
265 (define_constraint "YB"
267 A signed
10-bit constant."
268 (and (match_code "const_int")
269 (match_test "IMM10_OPERAND (ival)")))
271 (define_constraint "Yb"
273 (match_operand
0 "qi_mask_operand"))
275 (define_constraint "Yd"
277 A constant @code{move_operand} that can be safely loaded using
279 (and (match_operand
0 "move_operand")
280 (match_test "CONSTANT_P (op)")))
282 (define_constraint "Yh"
284 (match_operand
0 "hi_mask_operand"))
286 (define_constraint "Yw"
288 (match_operand
0 "si_mask_operand"))
290 (define_constraint "Yx"
292 (match_operand
0 "low_bitmask_operand"))
294 (define_constraint "YI"
296 A replicated vector const in which the replicated value is in the range
298 (and (match_code "const_vector")
299 (match_test "loongarch_const_vector_same_int_p (op, mode, -
512,
511)")))
301 (define_constraint "YC"
303 A replicated vector const in which the replicated value has a single
305 (and (match_code "const_vector")
306 (match_test "loongarch_const_vector_bitimm_set_p (op, mode)")))
308 (define_constraint "YZ"
310 A replicated vector const in which the replicated value has a single
312 (and (match_code "const_vector")
313 (match_test "loongarch_const_vector_bitimm_clr_p (op, mode)")))
315 (define_constraint "Unv5"
317 A replicated vector const in which the replicated value is in the range
319 (and (match_code "const_vector")
320 (match_test "loongarch_const_vector_same_int_p (op, mode, -
31,
0)")))
322 (define_constraint "Uuv5"
324 A replicated vector const in which the replicated value is in the range
326 (and (match_code "const_vector")
327 (match_test "loongarch_const_vector_same_int_p (op, mode,
0,
31)")))
329 (define_constraint "Usv5"
331 A replicated vector const in which the replicated value is in the range
333 (and (match_code "const_vector")
334 (match_test "loongarch_const_vector_same_int_p (op, mode, -
16,
15)")))
336 (define_constraint "Uuv6"
338 A replicated vector const in which the replicated value is in the range
340 (and (match_code "const_vector")
341 (match_test "loongarch_const_vector_same_int_p (op, mode,
0,
63)")))
343 (define_constraint "Urv8"
345 A replicated vector const with replicated byte values as well as elements"
346 (and (match_code "const_vector")
347 (match_test "loongarch_const_vector_same_bytes_p (op, mode)")))
349 (define_memory_constraint "ZC"
350 "A memory operand whose address is formed by a base register and offset
351 that is suitable for use in instructions with the same addressing mode
352 as @code{ll.w} and @code{sc.w}."
353 (and (match_code "mem")
354 (match_test "loongarch_14bit_shifted_offset_address_p (XEXP (op,
0), mode)")))
356 (define_memory_constraint "ZB"
358 An address that is held in a general-purpose register.
360 (and (match_code "mem")
361 (match_test "REG_P (XEXP (op,
0))")))
363 (define_address_constraint "ZD"
364 "An address operand whose address is formed by a base register
365 and offset that is suitable for use in instructions with the same
366 addressing mode as @code{preld}."
367 (match_test "loongarch_12bit_offset_address_p (op, mode)"))