1 /* Definitions of target machine for GNU compiler. LoongArch version.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 Contributed by Loongson Ltd.
4 Based on MIPS and RISC-V target for GNU compiler.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* LoongArch external variables defined in loongarch.cc. */
24 #include "config/loongarch/loongarch-opts.h"
25 #include "config/loongarch/loongarch-evolution.h"
27 #define SWITCHABLE_TARGET 1
29 #define TARGET_SUPPORTS_WIDE_INT 1
31 /* Macros to silence warnings about numbers being signed in traditional
32 C and unsigned in ISO C when compiled on 32-bit hosts. */
34 #define BITMASK_HIGH (((unsigned long) 1) << 31) /* 0x80000000 */
36 /* Run-time compilation parameters selecting different hardware subsets. */
38 /* Target CPU builtins. */
39 #define TARGET_CPU_CPP_BUILTINS() loongarch_cpu_cpp_builtins (pfile)
41 /* Default target_flags if no switches are specified. */
45 /* Make this compile time constant for libgcc2. */
47 #define TARGET_64BIT 1
49 #define TARGET_64BIT 0
51 #endif /* IN_LIBGCC2 */
53 #define TARGET_LIBGCC_SDATA_SECTION ".sdata"
55 /* This definition replaces the formerly used 'm' constraint with a
56 different constraint letter in order to avoid changing semantics of
57 the 'm' constraint when accepting new address formats in
58 TARGET_LEGITIMATE_ADDRESS_P. The constraint letter defined here
59 must not be used in insn definitions or inline assemblies. */
60 #define TARGET_MEM_CONSTRAINT 'w'
62 /* Tell collect what flags to pass to nm. */
64 #define NM_FLAGS "-Bn"
67 /* Registers may have a prefix which can be ignored when matching
68 user asm and register definitions. */
69 #ifndef REGISTER_PREFIX
70 #define REGISTER_PREFIX "$"
73 /* Local compiler-generated symbols must have a prefix that the assembler
76 #define LOCAL_LABEL_PREFIX "."
78 /* By default on the loongarch, external symbols do not have an underscore
81 #define USER_LABEL_PREFIX ""
83 #ifndef PREFERRED_DEBUGGING_TYPE
84 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
87 /* The size of DWARF addresses should be the same as the size of symbols
88 in the target file format. */
89 #define DWARF2_ADDR_SIZE (TARGET_64BIT ? 8 : 4)
91 /* By default, turn on GDB extensions. */
92 #define DEFAULT_GDB_EXTENSIONS 1
94 /* By default, produce dwarf version 2 format debugging output in response
95 to the ā-gā option. */
96 #define DWARF2_DEBUGGING_INFO 1
98 /* The mapping from gcc register number to DWARF 2 CFA column number. */
99 #define DWARF_FRAME_REGNUM(REGNO) loongarch_dwarf_regno[REGNO]
101 /* The DWARF 2 CFA column which tracks the return address. */
102 #define DWARF_FRAME_RETURN_COLUMN RETURN_ADDR_REGNUM
104 /* Before the prologue, RA lives in r1. */
105 #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)
107 /* Describe how we implement __builtin_eh_return. */
108 #define EH_RETURN_DATA_REGNO(N) \
109 ((N) < (4) ? (N) + GP_ARG_FIRST : INVALID_REGNUM)
111 #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, GP_ARG_FIRST + 4)
113 #define EH_USES(N) loongarch_eh_uses (N)
115 /* Offsets recorded in opcodes are a multiple of this alignment factor.
116 The default for this in 64-bit mode is 8, which causes problems with
117 SFmode register saves. */
118 #define DWARF_CIE_DATA_ALIGNMENT -4
120 /* Target machine storage layout. */
122 #define BITS_BIG_ENDIAN 0
123 #define BYTES_BIG_ENDIAN 0
124 #define WORDS_BIG_ENDIAN 0
126 #define MAX_BITS_PER_WORD 64
128 /* Width of a word, in units (bytes). */
129 #define UNITS_PER_WORD (TARGET_64BIT ? 8 : 4)
131 #define MIN_UNITS_PER_WORD 4
134 /* Width of a LSX vector register in bytes. */
135 #define UNITS_PER_LSX_REG 16
136 /* Width of a LSX vector register in bits. */
137 #define BITS_PER_LSX_REG (UNITS_PER_LSX_REG * BITS_PER_UNIT)
139 /* Width of a LASX vector register in bytes. */
140 #define UNITS_PER_LASX_REG 32
141 /* Width of a LASX vector register in bits. */
142 #define BITS_PER_LASX_REG (UNITS_PER_LASX_REG * BITS_PER_UNIT)
144 /* The largest size of value that can be held in floating-point
145 registers and moved with a single instruction. */
146 #define UNITS_PER_HWFPVALUE \
147 (TARGET_SOFT_FLOAT ? 0 : UNITS_PER_FP_REG)
149 /* The number of bytes in a double. */
150 #define UNITS_PER_DOUBLE (TYPE_PRECISION (double_type_node) / BITS_PER_UNIT)
152 /* Set the sizes of the core types. */
153 #define SHORT_TYPE_SIZE 16
154 #define INT_TYPE_SIZE 32
155 #define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32)
156 #define LONG_LONG_TYPE_SIZE 64
158 /* LONG_DOUBLE_TYPE_SIZE get poisoned, so add LA_ prefix. */
159 #define LA_LONG_DOUBLE_TYPE_SIZE (TARGET_64BIT ? 128 : 64)
161 /* Define the sizes of fixed-point types. */
162 #define SHORT_FRACT_TYPE_SIZE 8
163 #define FRACT_TYPE_SIZE 16
164 #define LONG_FRACT_TYPE_SIZE 32
165 #define LONG_LONG_FRACT_TYPE_SIZE 64
167 #define SHORT_ACCUM_TYPE_SIZE 16
168 #define ACCUM_TYPE_SIZE 32
169 #define LONG_ACCUM_TYPE_SIZE 64
170 #define LONG_LONG_ACCUM_TYPE_SIZE (TARGET_64BIT ? 128 : 64)
172 /* long double is not a fixed mode, but the idea is that, if we
173 support long double, we also want a 128-bit integer type. */
174 #define MAX_FIXED_MODE_SIZE LA_LONG_DOUBLE_TYPE_SIZE
176 /* Width in bits of a pointer. */
178 #define POINTER_SIZE (TARGET_64BIT ? 64 : 32)
181 /* Allocation boundary (in *bits*) for storing arguments in argument list. */
182 #define PARM_BOUNDARY BITS_PER_WORD
184 /* Allocation boundary (in *bits*) for the code of a function. */
185 #define FUNCTION_BOUNDARY 32
187 /* Alignment of field after `int : 0' in a structure. */
188 #define EMPTY_FIELD_BOUNDARY 32
190 /* Number of bits which any structure or union's size must be a multiple of.
191 Each structure or union's size is rounded up to a multiple of this. */
192 #define STRUCTURE_SIZE_BOUNDARY 8
194 /* There is no point aligning anything to a rounder boundary than
195 LA_LONG_DOUBLE_TYPE_SIZE, unless under LSX/LASX the bigggest alignment is
196 BITS_PER_LSX_REG/BITS_PER_LASX_REG/.. */
197 #define BIGGEST_ALIGNMENT \
198 (ISA_HAS_LASX? BITS_PER_LASX_REG \
199 : (ISA_HAS_LSX ? BITS_PER_LSX_REG : LA_LONG_DOUBLE_TYPE_SIZE))
201 /* All accesses must be aligned. */
202 #define STRICT_ALIGNMENT (TARGET_STRICT_ALIGN)
204 /* Define this if you wish to imitate the way many other C compilers
205 handle alignment of bitfields and the structures that contain
208 The behavior is that the type written for a bit-field (`int',
209 `short', or other integer type) imposes an alignment for the
210 entire structure, as if the structure really did contain an
211 ordinary field of that type. In addition, the bit-field is placed
212 within the structure so that it would fit within such a field,
213 not crossing a boundary for it.
215 Thus, on most machines, a bit-field whose type is written as `int'
216 would not cross a four-byte boundary, and would force four-byte
217 alignment for the whole structure. (The alignment used may not
218 be four bytes; it is controlled by the other alignment
221 If the macro is defined, its definition should be a C expression;
222 a nonzero value for the expression enables this behavior. */
224 #define PCC_BITFIELD_TYPE_MATTERS 1
226 /* If defined, a C expression to compute the alignment for a static
227 variable. TYPE is the data type, and ALIGN is the alignment that
228 the object would ordinarily have. The value of this macro is used
229 instead of that alignment to align the object.
231 If this macro is not defined, then ALIGN is used.
233 One use of this macro is to increase alignment of medium-size
234 data to make it all fit in fewer cache lines. Another is to
235 cause character arrays to be word-aligned so that `strcpy' calls
236 that copy constants to character arrays can be done inline. */
238 #undef DATA_ALIGNMENT
239 #define DATA_ALIGNMENT(TYPE, ALIGN) \
240 ((((ALIGN) < BITS_PER_WORD) \
241 && (TREE_CODE (TYPE) == ARRAY_TYPE \
242 || TREE_CODE (TYPE) == UNION_TYPE \
243 || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
245 /* We need this for the same reason as DATA_ALIGNMENT, namely to cause
246 character arrays to be word-aligned so that `strcpy' calls that copy
247 constants to character arrays can be done inline, and 'strcmp' can be
248 optimised to use word loads. */
249 #define LOCAL_ALIGNMENT(TYPE, ALIGN) DATA_ALIGNMENT (TYPE, ALIGN)
251 /* Define if operations between registers always perform the operation
252 on the full register even if a narrower mode is specified. */
253 #define WORD_REGISTER_OPERATIONS 1
255 /* When in 64-bit mode, move insns will sign extend SImode and FCCmode
256 moves. All other references are zero extended. */
257 #define LOAD_EXTEND_OP(MODE) \
258 (TARGET_64BIT && ((MODE) == SImode || (MODE) == FCCmode) ? SIGN_EXTEND \
261 /* Define this macro if it is advisable to hold scalars in registers
262 in a wider mode than that declared by the program. In such cases,
263 the value is constrained to be within the bounds of the declared
264 type, but kept valid in the wider mode. The signedness of the
265 extension may differ from that of the type. */
267 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
268 if (GET_MODE_CLASS (MODE) == MODE_INT \
269 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
271 if ((MODE) == SImode) \
276 /* Pmode is always the same as ptr_mode, but not always the same as word_mode.
277 Extensions of pointers to word_mode must be signed. */
278 #define POINTERS_EXTEND_UNSIGNED false
280 /* Define if loading short immediate values into registers sign extends. */
281 #define SHORT_IMMEDIATES_SIGN_EXTEND 1
283 /* The clz.{w/d}, ctz.{w/d} instructions have the natural values at 0. */
285 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
286 ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
287 #define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
288 ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
290 /* Standard register usage. */
292 /* Number of hardware registers. We have:
294 - 32 integer registers
295 - 32 floating point registers
296 - 8 condition code registers
299 - FRAME_POINTER_REGNUM
302 #define FIRST_PSEUDO_REGISTER 74
304 /* zero, tp, sp and x are fixed. */
305 #define FIXED_REGISTERS \
306 { /* General registers. */ \
307 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
308 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
309 /* Floating-point registers. */ \
310 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
311 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
313 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}
315 /* The call RTLs themselves clobber ra. */
316 #define CALL_USED_REGISTERS \
317 { /* General registers. */ \
318 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
319 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
320 /* Floating-point registers. */ \
321 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
322 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, \
324 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
326 /* Internal macros to classify a register number as to whether it's a
327 general purpose register, a floating point register, or a status
330 #define GP_REG_FIRST 0
331 #define GP_REG_LAST 31
332 #define GP_REG_NUM (GP_REG_LAST - GP_REG_FIRST + 1)
334 #define FP_REG_FIRST 32
335 #define FP_REG_LAST 63
336 #define FP_REG_NUM (FP_REG_LAST - FP_REG_FIRST + 1)
337 #define LSX_REG_FIRST FP_REG_FIRST
338 #define LSX_REG_LAST FP_REG_LAST
339 #define LSX_REG_NUM FP_REG_NUM
341 #define LASX_REG_FIRST FP_REG_FIRST
342 #define LASX_REG_LAST FP_REG_LAST
343 #define LASX_REG_NUM FP_REG_NUM
345 /* The DWARF 2 CFA column which tracks the return address from a
346 signal handler context. This means that to maintain backwards
347 compatibility, no hard register can be assigned this column if it
348 would need to be handled by the DWARF unwinder. */
349 #define DWARF_ALT_FRAME_RETURN_COLUMN 72
351 #define FCC_REG_FIRST 64
352 #define FCC_REG_LAST 71
353 #define FCC_REG_NUM (FCC_REG_LAST - FCC_REG_FIRST + 1)
355 #define GP_REG_P(REGNO) \
356 ((unsigned int) ((int) (REGNO) - GP_REG_FIRST) < GP_REG_NUM)
357 #define FP_REG_P(REGNO) \
358 ((unsigned int) ((int) (REGNO) - FP_REG_FIRST) < FP_REG_NUM)
359 #define FCC_REG_P(REGNO) \
360 ((unsigned int) ((int) (REGNO) - FCC_REG_FIRST) < FCC_REG_NUM)
361 #define LSX_REG_P(REGNO) \
362 ((unsigned int) ((int) (REGNO) - LSX_REG_FIRST) < LSX_REG_NUM)
363 #define LASX_REG_P(REGNO) \
364 ((unsigned int) ((int) (REGNO) - LASX_REG_FIRST) < LASX_REG_NUM)
366 #define FP_REG_RTX_P(X) (REG_P (X) && FP_REG_P (REGNO (X)))
367 #define LSX_REG_RTX_P(X) (REG_P (X) && LSX_REG_P (REGNO (X)))
368 #define LASX_REG_RTX_P(X) (REG_P (X) && LASX_REG_P (REGNO (X)))
370 /* Select a register mode required for caller save of hard regno REGNO. */
371 #define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \
372 loongarch_hard_regno_caller_save_mode (REGNO, NREGS, MODE)
374 /* Register to use for pushing function arguments. */
375 #define STACK_POINTER_REGNUM (GP_REG_FIRST + 3)
377 /* These two registers don't really exist: they get eliminated to either
378 the stack or hard frame pointer. */
379 #define ARG_POINTER_REGNUM 72
380 #define FRAME_POINTER_REGNUM 73
382 #define HARD_FRAME_POINTER_REGNUM (GP_REG_FIRST + 22)
384 #define HARD_FRAME_POINTER_IS_FRAME_POINTER 0
385 #define HARD_FRAME_POINTER_IS_ARG_POINTER 0
387 /* Register in which static-chain is passed to a function. */
388 #define STATIC_CHAIN_REGNUM (GP_REG_FIRST + 20) /* $t8 */
390 #define GP_TEMP_FIRST (GP_REG_FIRST + 12)
391 #define LARCH_PROLOGUE_TEMP_REGNUM (GP_TEMP_FIRST + 1)
392 #define LARCH_PROLOGUE_TEMP2_REGNUM (GP_TEMP_FIRST)
393 #define LARCH_PROLOGUE_TEMP3_REGNUM (GP_TEMP_FIRST + 2)
394 #define LARCH_EPILOGUE_TEMP_REGNUM (GP_TEMP_FIRST)
396 #define CALLEE_SAVED_REG_NUMBER(REGNO) \
397 ((REGNO) >= 22 && (REGNO) <= 31 ? (REGNO) - 22 : -1)
399 #define LARCH_PROLOGUE_TEMP(MODE) \
400 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP_REGNUM)
401 #define LARCH_PROLOGUE_TEMP2(MODE) \
402 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP2_REGNUM)
403 #define LARCH_PROLOGUE_TEMP3(MODE) \
404 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP3_REGNUM)
405 #define LARCH_EPILOGUE_TEMP(MODE) \
406 gen_rtx_REG (MODE, LARCH_EPILOGUE_TEMP_REGNUM)
408 /* Define this macro if it is as good or better to call a constant
409 function address than to call an address kept in a register. */
410 #define NO_FUNCTION_CSE 1
412 #define THREAD_POINTER_REGNUM (GP_REG_FIRST + 2)
414 /* Define the classes of registers for register constraints in the
415 machine description. Also define ranges of constants.
417 One of the classes must always be named ALL_REGS and include all hard regs.
418 If there is more than one class, another class must be named NO_REGS
419 and contain no registers.
421 The name GENERAL_REGS must be the name of a class (or an alias for
422 another name such as ALL_REGS). This is the class of registers
423 that is allowed by "r" in a register constraint.
424 Also, registers outside this class are allocated only when
425 instructions express preferences for them.
427 The classes must be numbered in nondecreasing order; that is,
428 a larger-numbered class must never be contained completely
429 in a smaller-numbered class.
431 For any two classes, it is very desirable that there be another
432 class that represents their union. */
436 NO_REGS
, /* no registers in set */
437 SIBCALL_REGS
, /* registers used by indirect sibcalls */
438 JIRL_REGS
, /* registers used by indirect calls */
439 CSR_REGS
, /* integer registers except for $r0 and $r1 for lcsr. */
440 GR_REGS
, /* integer registers */
441 FP_REGS
, /* floating point registers */
442 FCC_REGS
, /* status registers (fp status) */
443 FRAME_REGS
, /* arg pointer and frame pointer */
444 ALL_REGS
, /* all registers */
445 LIM_REG_CLASSES
/* max value + 1 */
448 #define N_REG_CLASSES (int) LIM_REG_CLASSES
450 #define GENERAL_REGS GR_REGS
452 /* An initializer containing the names of the register classes as C
453 string constants. These names are used in writing some of the
456 #define REG_CLASS_NAMES \
469 /* An initializer containing the contents of the register classes,
470 as integers which are bit masks. The Nth integer specifies the
471 contents of class N. The way the integer MASK is interpreted is
472 that register R is in the class if `MASK & (1 << R)' is 1.
474 When the machine has more than 32 registers, an integer does not
475 suffice. Then the integers are replaced by sub-initializers,
476 braced groupings containing several integers. Each
477 sub-initializer must be suitable as an initializer for the type
478 `HARD_REG_SET' which is defined in `hard-reg-set.h'. */
480 #define REG_CLASS_CONTENTS \
482 { 0x00000000, 0x00000000, 0x00000000 }, /* NO_REGS */ \
483 { 0x001fd000, 0x00000000, 0x00000000 }, /* SIBCALL_REGS */ \
484 { 0xff9ffff0, 0x00000000, 0x00000000 }, /* JIRL_REGS */ \
485 { 0xfffffffc, 0x00000000, 0x00000000 }, /* CSR_REGS */ \
486 { 0xffffffff, 0x00000000, 0x00000000 }, /* GR_REGS */ \
487 { 0x00000000, 0xffffffff, 0x00000000 }, /* FP_REGS */ \
488 { 0x00000000, 0x00000000, 0x000000ff }, /* FCC_REGS */ \
489 { 0x00000000, 0x00000000, 0x00000300 }, /* FRAME_REGS */ \
490 { 0xffffffff, 0xffffffff, 0x000003ff } /* ALL_REGS */ \
493 /* A C expression whose value is a register class containing hard
494 register REGNO. In general there is more that one such class;
495 choose a class which is "minimal", meaning that no smaller class
496 also contains the register. */
498 #define REGNO_REG_CLASS(REGNO) loongarch_regno_to_class[(REGNO)]
500 /* A macro whose definition is the name of the class to which a
501 valid base register must belong. A base register is one used in
502 an address which is the register value plus a displacement. */
504 #define BASE_REG_CLASS (GR_REGS)
506 /* A macro whose definition is the name of the class to which a
507 valid index register must belong. An index register is one used
508 in an address where its value is either multiplied by a scale
509 factor or added to another register (as well as added to a
512 #define INDEX_REG_CLASS GR_REGS
514 /* We generally want to put call-clobbered registers ahead of
515 call-saved ones. (IRA expects this.) */
517 #define REG_ALLOC_ORDER \
518 { /* Call-clobbered GPRs. */ \
519 12, 13, 14, 15, 16, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 1, \
520 /* Call-saved GPRs. */ \
521 23, 24, 25, 26, 27, 28, 29, 30, 31, \
522 /* GPRs that can never be exposed to the register allocator. */ \
524 /* Call-clobbered FPRs. */ \
525 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, \
526 48, 49, 50, 51,52, 53, 54, 55, \
527 56, 57, 58, 59, 60, 61, 62, 63, \
528 /* None of the remaining classes have defined call-saved \
530 64, 65, 66, 67, 68, 69, 70, 71, 72, 73}
533 #define IMM_REACH (HOST_WIDE_INT_1 << IMM_BITS)
534 #define HWIT_1U HOST_WIDE_INT_1U
536 /* True if VALUE is an unsigned 6-bit number. */
538 #define UIMM6_OPERAND(VALUE) (((VALUE) & ~(unsigned HOST_WIDE_INT) 0x3f) == 0)
540 /* True if VALUE is a signed 10-bit number. */
542 #define IMM10_OPERAND(VALUE) ((unsigned HOST_WIDE_INT) (VALUE) + 0x200 < 0x400)
544 /* True if VALUE is a signed 12-bit number. */
546 #define IMM12_OPERAND(VALUE) \
547 ((unsigned HOST_WIDE_INT) (VALUE) + IMM_REACH / 2 < IMM_REACH)
549 /* True if VALUE is a signed 13-bit number. */
551 #define IMM13_OPERAND(VALUE) \
552 ((unsigned HOST_WIDE_INT) (VALUE) + 0x1000 < 0x2000)
554 /* True if VALUE is a signed 16-bit number. */
556 #define IMM16_OPERAND(VALUE) \
557 ((unsigned HOST_WIDE_INT) (VALUE) + 0x8000 < 0x10000)
559 /* True if VALUE is an unsigned 12-bit number. */
561 #define IMM12_OPERAND_UNSIGNED(VALUE) \
562 (((VALUE) & ~(unsigned HOST_WIDE_INT) (IMM_REACH - 1)) == 0)
564 /* True if VALUE can be loaded into a register using LU12I. */
566 #define LU12I_OPERAND(VALUE) \
567 (((VALUE) | ((HWIT_1U << 31) - IMM_REACH)) == ((HWIT_1U << 31) - IMM_REACH) \
568 || ((VALUE) | ((HWIT_1U << 31) - IMM_REACH)) + IMM_REACH == 0)
570 /* True if VALUE can be loaded into a register using LU32I. */
572 #define LU32I_OPERAND(VALUE) \
573 (((VALUE) | (((HWIT_1U << 19) - 1) << 32)) == (((HWIT_1U << 19) - 1) << 32) \
574 || ((VALUE) | (((HWIT_1U << 19) - 1) << 32)) + (HWIT_1U << 32) == 0)
576 /* True if VALUE can be loaded into a register using LU52I. */
578 #define HWIT_UC_0xFFF HOST_WIDE_INT_UC(0xfff)
579 #define LU52I_OPERAND(VALUE) \
580 (((VALUE) | (HWIT_UC_0xFFF << 52)) == (HWIT_UC_0xFFF << 52))
582 /* Return a value X with the low 12 bits clear, and such that
583 VALUE - X is a signed 12-bit value. */
585 #define CONST_HIGH_PART(VALUE) (((VALUE) + (IMM_REACH / 2)) & ~(IMM_REACH - 1))
587 #define CONST_LOW_PART(VALUE) ((VALUE) - CONST_HIGH_PART (VALUE))
589 /* True if VALUE can be added onto a register with one addu16i.d
592 #define ADDU16I_OPERAND(VALUE) \
593 (TARGET_64BIT && (((VALUE) & 0xffff) == 0 \
594 && IMM16_OPERAND ((HOST_WIDE_INT) (VALUE) / 65536)))
596 /* True if VALUE can be added onto a register with two addi.{d/w}
597 instructions, but not one addi.{d/w} instruction. */
598 #define DUAL_IMM12_OPERAND(VALUE) \
599 (IN_RANGE ((VALUE), -4096, 4094) && !IMM12_OPERAND (VALUE))
601 /* True if VALUE can be added onto a register with two addu16i.d
602 instruction, but not one addu16i.d instruction. */
603 #define DUAL_ADDU16I_OPERAND(VALUE) \
604 (TARGET_64BIT && (((VALUE) & 0xffff) == 0 \
605 && !ADDU16I_OPERAND (VALUE) \
606 && IN_RANGE ((VALUE) / 65536, -0x10000, 0xfffe)))
608 #define IMM12_INT(X) IMM12_OPERAND (INTVAL (X))
609 #define IMM12_INT_UNSIGNED(X) IMM12_OPERAND_UNSIGNED (INTVAL (X))
610 #define LU12I_INT(X) LU12I_OPERAND (INTVAL (X))
611 #define LU32I_INT(X) LU32I_OPERAND (INTVAL (X))
612 #define LU52I_INT(X) LU52I_OPERAND (INTVAL (X))
613 #define LARCH_12BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -2048, 2047))
614 #define LARCH_9BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -256, 255))
615 #define LARCH_16BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -32768, 32767))
616 #define LARCH_SHIFT_2_OFFSET_P(OFFSET) (((OFFSET) & 0x3) == 0)
618 /* Return the maximum number of consecutive registers
619 needed to represent mode MODE in a register of class CLASS. */
621 #define CLASS_MAX_NREGS(CLASS, MODE) loongarch_class_max_nregs (CLASS, MODE)
623 /* Stack layout; function entry, exit and calling. */
625 #define STACK_GROWS_DOWNWARD 1
627 #define FRAME_GROWS_DOWNWARD 1
629 #define RETURN_ADDR_RTX loongarch_return_addr
631 /* Similarly, don't use the least-significant bit to tell pointers to
632 code from vtable index. */
634 #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_delta
636 #define ELIMINABLE_REGS \
638 {ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
639 {ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
640 {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
641 {FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
644 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
645 (OFFSET) = loongarch_initial_elimination_offset ((FROM), (TO))
647 /* Allocate stack space for arguments at the beginning of each function. */
648 #define ACCUMULATE_OUTGOING_ARGS 1
650 /* The argument pointer always points to the first argument. */
651 #define FIRST_PARM_OFFSET(FNDECL) 0
653 #define REG_PARM_STACK_SPACE(FNDECL) 0
655 /* Define this if it is the responsibility of the caller to
656 allocate the area reserved for arguments passed in registers.
657 If `ACCUMULATE_OUTGOING_ARGS' is also defined, the only effect
658 of this macro is to determine whether the space is included in
659 `crtl->outgoing_args_size'. */
660 #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1
662 #define STACK_BOUNDARY (TARGET_ABI_LP64 ? 128 : 64)
664 /* This value controls how many pages we manually unroll the loop for when
665 generating stack clash probes. */
666 #define STACK_CLASH_MAX_UNROLL_PAGES 4
668 /* Symbolic macros for the registers used to return integer and floating
671 #define GP_RETURN (GP_REG_FIRST + 4)
672 #define FP_RETURN ((TARGET_SOFT_FLOAT_ABI) ? GP_RETURN : (FP_REG_FIRST + 0))
674 #define MAX_ARGS_IN_REGISTERS 8
676 /* Symbolic macros for the first/last argument registers. */
678 #define GP_ARG_FIRST (GP_REG_FIRST + 4)
679 #define GP_ARG_LAST (GP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
680 #define FP_ARG_FIRST (FP_REG_FIRST + 0)
681 #define FP_ARG_LAST (FP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
683 /* True if MODE is vector and supported in a LSX vector register. */
684 #define LSX_SUPPORTED_MODE_P(MODE) \
686 && GET_MODE_SIZE (MODE) == UNITS_PER_LSX_REG \
687 && (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
688 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT))
690 #define LASX_SUPPORTED_MODE_P(MODE) \
692 && (GET_MODE_SIZE (MODE) == UNITS_PER_LSX_REG \
693 ||GET_MODE_SIZE (MODE) == UNITS_PER_LASX_REG) \
694 && (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
695 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT))
697 #define RECIP_MASK_NONE 0x00
698 #define RECIP_MASK_DIV 0x01
699 #define RECIP_MASK_SQRT 0x02
700 #define RECIP_MASK_RSQRT 0x04
701 #define RECIP_MASK_VEC_DIV 0x08
702 #define RECIP_MASK_VEC_SQRT 0x10
703 #define RECIP_MASK_VEC_RSQRT 0x20
704 #define RECIP_MASK_ALL (RECIP_MASK_DIV | RECIP_MASK_SQRT \
705 | RECIP_MASK_RSQRT | RECIP_MASK_VEC_SQRT \
706 | RECIP_MASK_VEC_DIV | RECIP_MASK_VEC_RSQRT)
708 #define TARGET_RECIP_DIV \
709 ((recip_mask & RECIP_MASK_DIV) != 0 && ISA_HAS_FRECIPE)
710 #define TARGET_RECIP_SQRT \
711 ((recip_mask & RECIP_MASK_SQRT) != 0 && ISA_HAS_FRECIPE)
712 #define TARGET_RECIP_RSQRT \
713 ((recip_mask & RECIP_MASK_RSQRT) != 0 && ISA_HAS_FRECIPE)
714 #define TARGET_RECIP_VEC_DIV \
715 ((recip_mask & RECIP_MASK_VEC_DIV) != 0 && ISA_HAS_FRECIPE)
716 #define TARGET_RECIP_VEC_SQRT \
717 ((recip_mask & RECIP_MASK_VEC_SQRT) != 0 && ISA_HAS_FRECIPE)
718 #define TARGET_RECIP_VEC_RSQRT \
719 ((recip_mask & RECIP_MASK_VEC_RSQRT) != 0 && ISA_HAS_FRECIPE)
721 /* 1 if N is a possible register number for function argument passing.
722 We have no FP argument registers when soft-float. */
724 /* Accept arguments in a0-a7, and in fa0-fa7 if permitted by the ABI. */
725 #define FUNCTION_ARG_REGNO_P(N) \
726 (IN_RANGE ((N), GP_ARG_FIRST, GP_ARG_LAST) \
727 || (UNITS_PER_FP_ARG && IN_RANGE ((N), FP_ARG_FIRST, FP_ARG_LAST)))
730 /* Number of integer registers used so far, up to MAX_ARGS_IN_REGISTERS. */
731 unsigned int num_gprs
;
733 /* Number of floating-point registers used so far, likewise. */
734 unsigned int num_fprs
;
738 /* Initialize a variable CUM of type CUMULATIVE_ARGS
739 for a call to a function whose data type is FNTYPE.
740 For a library call, FNTYPE is 0. */
742 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
743 memset (&(CUM), 0, sizeof (CUM))
745 #define EPILOGUE_USES(REGNO) loongarch_epilogue_uses (REGNO)
747 /* Treat LOC as a byte offset from the stack pointer and round it up
748 to the next fully-aligned offset. */
749 #define LARCH_STACK_ALIGN(LOC) \
750 (TARGET_ABI_LP64 ? ROUND_UP ((LOC), 16) : ROUND_UP ((LOC), 8))
752 #define MCOUNT_NAME "_mcount"
754 /* Emit rtl for profiling. Output assembler code to FILE
755 to call "_mcount" for profiling a function entry. */
756 #define PROFILE_HOOK(LABEL) \
759 ra = get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM); \
760 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
761 emit_library_call (fun, LCT_NORMAL, VOIDmode, ra, Pmode); \
764 /* All the work done in PROFILE_HOOK, but still required. */
765 #define FUNCTION_PROFILER(STREAM, LABELNO) do { } while (0)
767 #define NO_PROFILE_COUNTERS 1
769 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
770 the stack pointer does not matter. The value is tested only in
771 functions that have frame pointers.
772 No definition is equivalent to always zero. */
774 #define EXIT_IGNORE_STACK 1
776 /* Trampolines are a block of code followed by two pointers. */
778 #define TRAMPOLINE_CODE_SIZE 16
779 #define TRAMPOLINE_SIZE \
780 ((Pmode == SImode) ? TRAMPOLINE_CODE_SIZE \
781 : (TRAMPOLINE_CODE_SIZE + POINTER_SIZE * 2))
782 #define TRAMPOLINE_ALIGNMENT POINTER_SIZE
784 /* loongarch_trampoline_init calls this library function to flush
785 program and data caches. */
787 #ifndef CACHE_FLUSH_FUNC
788 #define CACHE_FLUSH_FUNC "_flush_cache"
791 /* Addressing modes, and classification of registers for them. */
793 #define REGNO_OK_FOR_INDEX_P(REGNO) \
794 loongarch_regno_mode_ok_for_base_p (REGNO, VOIDmode, 1)
796 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) \
797 loongarch_regno_mode_ok_for_base_p (REGNO, MODE, 1)
799 /* Maximum number of registers that can appear in a valid memory address. */
801 #define MAX_REGS_PER_ADDRESS 2
803 /* Check for constness inline but use loongarch_legitimate_address_p
804 to check whether a constant really is an address. */
806 #define CONSTANT_ADDRESS_P(X) (CONSTANT_P (X) && memory_address_p (SImode, X))
808 /* This handles the magic '..CURRENT_FUNCTION' symbol, which means
809 'the start of the function that this code is output in'. */
811 #define ASM_OUTPUT_LABELREF(FILE, NAME) \
814 if (strcmp (NAME, "..CURRENT_FUNCTION") == 0) \
815 asm_fprintf ((FILE), "%U%s", \
816 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \
818 asm_fprintf ((FILE), "%U%s", (NAME)); \
822 #define CASE_VECTOR_MODE Pmode
824 #define CASE_VECTOR_SHORTEN_MODE(MIN, MAX, BODY) Pmode
826 /* Define this as 1 if `char' should by default be signed; else as 0. */
827 #ifndef DEFAULT_SIGNED_CHAR
828 #define DEFAULT_SIGNED_CHAR 1
831 /* The SPARC port says:
832 The maximum number of bytes that a single instruction
833 can move quickly between memory and registers or between
834 two memory locations. */
835 #define MOVE_MAX UNITS_PER_WORD
836 #define MAX_MOVE_MAX 8
838 /* The SPARC port says:
839 Nonzero if access to memory by bytes is slow and undesirable.
840 For RISC chips, it means that access to memory by bytes is no
841 better than access by words when possible, so grab a whole word
842 and maybe make use of that. */
843 #define SLOW_BYTE_ACCESS 1
845 /* Standard LoongArch integer shifts truncate the shift amount to the
846 width of the shifted operand. */
847 #define SHIFT_COUNT_TRUNCATED 1
849 /* Specify the machine mode that pointers have.
850 After generation of rtl, the compiler makes no further distinction
851 between pointers and any other objects of this machine mode. */
854 #define Pmode (TARGET_64BIT ? DImode : SImode)
857 /* Give call MEMs SImode since it is the "most permissive" mode
858 for both 32-bit and 64-bit targets. */
860 #define FUNCTION_MODE SImode
862 /* We allocate $fcc registers by hand and can't cope with moves of
863 CCmode registers to and from pseudos (or memory). */
864 #define AVOID_CCMODE_COPIES
866 /* A C expression for the cost of a branch instruction. A value of
867 1 is the default; other values are interpreted relative to that. */
869 #define BRANCH_COST(speed_p, predictable_p) la_branch_cost
870 #define LOGICAL_OP_NON_SHORT_CIRCUIT 0
872 /* Return the asm template for a conditional branch instruction.
873 OPCODE is the opcode's mnemonic and OPERANDS is the asm template for
875 #define LARCH_BRANCH(OPCODE, OPERANDS) OPCODE "\t" OPERANDS
877 /* Control the assembler format that we output. */
879 /* Output to assembler file text saying following lines
880 may contain character constants, extra white space, comments, etc. */
883 #define ASM_APP_ON " #APP\n"
886 /* Output to assembler file text saying following lines
887 no longer contain unusual constructs. */
890 #define ASM_APP_OFF " #NO_APP\n"
893 #define REGISTER_NAMES \
894 { "$r0", "$r1", "$r2", "$r3", "$r4", "$r5", "$r6", "$r7", \
895 "$r8", "$r9", "$r10", "$r11", "$r12", "$r13", "$r14", "$r15", \
896 "$r16", "$r17", "$r18", "$r19", "$r20", "$r21", "$r22", "$r23", \
897 "$r24", "$r25", "$r26", "$r27", "$r28", "$r29", "$r30", "$r31", \
898 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", \
899 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", \
900 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", \
901 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", \
902 "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4","$fcc5","$fcc6","$fcc7", \
905 /* This macro defines additional names for hard registers. */
907 #define ADDITIONAL_REGISTER_NAMES \
909 { "zero", 0 + GP_REG_FIRST }, \
910 { "ra", 1 + GP_REG_FIRST }, \
911 { "tp", 2 + GP_REG_FIRST }, \
912 { "sp", 3 + GP_REG_FIRST }, \
913 { "a0", 4 + GP_REG_FIRST }, \
914 { "a1", 5 + GP_REG_FIRST }, \
915 { "a2", 6 + GP_REG_FIRST }, \
916 { "a3", 7 + GP_REG_FIRST }, \
917 { "a4", 8 + GP_REG_FIRST }, \
918 { "a5", 9 + GP_REG_FIRST }, \
919 { "a6", 10 + GP_REG_FIRST }, \
920 { "a7", 11 + GP_REG_FIRST }, \
921 { "t0", 12 + GP_REG_FIRST }, \
922 { "t1", 13 + GP_REG_FIRST }, \
923 { "t2", 14 + GP_REG_FIRST }, \
924 { "t3", 15 + GP_REG_FIRST }, \
925 { "t4", 16 + GP_REG_FIRST }, \
926 { "t5", 17 + GP_REG_FIRST }, \
927 { "t6", 18 + GP_REG_FIRST }, \
928 { "t7", 19 + GP_REG_FIRST }, \
929 { "t8", 20 + GP_REG_FIRST }, \
930 { "x", 21 + GP_REG_FIRST }, \
931 { "fp", 22 + GP_REG_FIRST }, \
932 { "s9", 22 + GP_REG_FIRST }, \
933 { "s0", 23 + GP_REG_FIRST }, \
934 { "s1", 24 + GP_REG_FIRST }, \
935 { "s2", 25 + GP_REG_FIRST }, \
936 { "s3", 26 + GP_REG_FIRST }, \
937 { "s4", 27 + GP_REG_FIRST }, \
938 { "s5", 28 + GP_REG_FIRST }, \
939 { "s6", 29 + GP_REG_FIRST }, \
940 { "s7", 30 + GP_REG_FIRST }, \
941 { "s8", 31 + GP_REG_FIRST }, \
942 { "v0", 4 + GP_REG_FIRST }, \
943 { "v1", 5 + GP_REG_FIRST }, \
944 { "vr0", 0 + FP_REG_FIRST }, \
945 { "vr1", 1 + FP_REG_FIRST }, \
946 { "vr2", 2 + FP_REG_FIRST }, \
947 { "vr3", 3 + FP_REG_FIRST }, \
948 { "vr4", 4 + FP_REG_FIRST }, \
949 { "vr5", 5 + FP_REG_FIRST }, \
950 { "vr6", 6 + FP_REG_FIRST }, \
951 { "vr7", 7 + FP_REG_FIRST }, \
952 { "vr8", 8 + FP_REG_FIRST }, \
953 { "vr9", 9 + FP_REG_FIRST }, \
954 { "vr10", 10 + FP_REG_FIRST }, \
955 { "vr11", 11 + FP_REG_FIRST }, \
956 { "vr12", 12 + FP_REG_FIRST }, \
957 { "vr13", 13 + FP_REG_FIRST }, \
958 { "vr14", 14 + FP_REG_FIRST }, \
959 { "vr15", 15 + FP_REG_FIRST }, \
960 { "vr16", 16 + FP_REG_FIRST }, \
961 { "vr17", 17 + FP_REG_FIRST }, \
962 { "vr18", 18 + FP_REG_FIRST }, \
963 { "vr19", 19 + FP_REG_FIRST }, \
964 { "vr20", 20 + FP_REG_FIRST }, \
965 { "vr21", 21 + FP_REG_FIRST }, \
966 { "vr22", 22 + FP_REG_FIRST }, \
967 { "vr23", 23 + FP_REG_FIRST }, \
968 { "vr24", 24 + FP_REG_FIRST }, \
969 { "vr25", 25 + FP_REG_FIRST }, \
970 { "vr26", 26 + FP_REG_FIRST }, \
971 { "vr27", 27 + FP_REG_FIRST }, \
972 { "vr28", 28 + FP_REG_FIRST }, \
973 { "vr29", 29 + FP_REG_FIRST }, \
974 { "vr30", 30 + FP_REG_FIRST }, \
975 { "vr31", 31 + FP_REG_FIRST }, \
976 { "xr0", 0 + FP_REG_FIRST }, \
977 { "xr1", 1 + FP_REG_FIRST }, \
978 { "xr2", 2 + FP_REG_FIRST }, \
979 { "xr3", 3 + FP_REG_FIRST }, \
980 { "xr4", 4 + FP_REG_FIRST }, \
981 { "xr5", 5 + FP_REG_FIRST }, \
982 { "xr6", 6 + FP_REG_FIRST }, \
983 { "xr7", 7 + FP_REG_FIRST }, \
984 { "xr8", 8 + FP_REG_FIRST }, \
985 { "xr9", 9 + FP_REG_FIRST }, \
986 { "xr10", 10 + FP_REG_FIRST }, \
987 { "xr11", 11 + FP_REG_FIRST }, \
988 { "xr12", 12 + FP_REG_FIRST }, \
989 { "xr13", 13 + FP_REG_FIRST }, \
990 { "xr14", 14 + FP_REG_FIRST }, \
991 { "xr15", 15 + FP_REG_FIRST }, \
992 { "xr16", 16 + FP_REG_FIRST }, \
993 { "xr17", 17 + FP_REG_FIRST }, \
994 { "xr18", 18 + FP_REG_FIRST }, \
995 { "xr19", 19 + FP_REG_FIRST }, \
996 { "xr20", 20 + FP_REG_FIRST }, \
997 { "xr21", 21 + FP_REG_FIRST }, \
998 { "xr22", 22 + FP_REG_FIRST }, \
999 { "xr23", 23 + FP_REG_FIRST }, \
1000 { "xr24", 24 + FP_REG_FIRST }, \
1001 { "xr25", 25 + FP_REG_FIRST }, \
1002 { "xr26", 26 + FP_REG_FIRST }, \
1003 { "xr27", 27 + FP_REG_FIRST }, \
1004 { "xr28", 28 + FP_REG_FIRST }, \
1005 { "xr29", 29 + FP_REG_FIRST }, \
1006 { "xr30", 30 + FP_REG_FIRST }, \
1007 { "xr31", 31 + FP_REG_FIRST } \
1010 /* Globalizing directive for a label. */
1011 #define GLOBAL_ASM_OP "\t.globl\t"
1013 /* This says how to output an external. It would be possible not to
1014 output anything and let undefined symbol become external. However
1015 the assembler uses length information on externals to allocate in
1016 data/sdata bss/sbss, thereby saving exec time. */
1018 #undef ASM_OUTPUT_EXTERNAL
1019 #define ASM_OUTPUT_EXTERNAL(STREAM, DECL, NAME) \
1020 loongarch_output_external (STREAM, DECL, NAME)
1022 /* This is how to store into the string LABEL
1023 the symbol_ref name of an internal numbered label where
1024 PREFIX is the class of label and NUM is the number within the class.
1025 This is suitable for output with `assemble_name'. */
1027 #undef ASM_GENERATE_INTERNAL_LABEL
1028 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
1029 sprintf ((LABEL), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX), (long) (NUM))
1031 /* Print debug labels as "foo = ." rather than "foo:" because they should
1032 represent a byte pointer rather than an ISA-encoded address. This is
1033 particularly important for code like:
1038 .section .gcc_except_table,...
1040 .uleb128 foo-$LFBxxx
1042 The .uleb128 requies $LFBxxx to match the FDE start address, which is
1043 likewise a byte pointer rather than an ISA-encoded address.
1045 At the time of writing, this hook is not used for the function end
1053 #define ASM_OUTPUT_DEBUG_LABEL(FILE, PREFIX, NUM) \
1054 fprintf (FILE, "%s%s%d = .\n", LOCAL_LABEL_PREFIX, PREFIX, NUM)
1056 /* This is how to output an element of a case-vector that is absolute. */
1058 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE) \
1059 fprintf (STREAM, "\t%s\t%sL%d\n", ptr_mode == DImode ? ".dword" : ".word", \
1060 LOCAL_LABEL_PREFIX, VALUE)
1062 /* This is how to output an element of a case-vector. */
1064 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL) \
1067 fprintf (STREAM, "\t%s\t%sL%d-%sL%d\n", \
1068 ptr_mode == DImode ? ".dword" : ".word", LOCAL_LABEL_PREFIX, \
1069 VALUE, LOCAL_LABEL_PREFIX, REL); \
1073 #define JUMP_TABLES_IN_TEXT_SECTION 0
1075 /* This is how to output an assembler line
1076 that says to advance the location counter
1077 to a multiple of 2**LOG bytes. */
1079 #define ASM_OUTPUT_ALIGN(STREAM, LOG) fprintf (STREAM, "\t.align\t%d\n", (LOG))
1081 /* This is how to output an assembler line to advance the location
1082 counter by SIZE bytes. */
1084 #undef ASM_OUTPUT_SKIP
1085 #define ASM_OUTPUT_SKIP(STREAM, SIZE) \
1086 fprintf (STREAM, "\t.space\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n", (SIZE))
1088 /* This is how to output a string. */
1089 #undef ASM_OUTPUT_ASCII
1090 #define ASM_OUTPUT_ASCII loongarch_output_ascii
1092 /* Define the strings to put out for each section in the object file. */
1093 #define TEXT_SECTION_ASM_OP "\t.text" /* instructions */
1094 #define DATA_SECTION_ASM_OP "\t.data" /* large data */
1096 #undef READONLY_DATA_SECTION_ASM_OP
1097 #define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata" /* read-only data */
1099 #define ASM_OUTPUT_REG_PUSH(STREAM, REGNO) \
1102 fprintf (STREAM, "\t%s\t%s,%s,-8\n\t%s\t%s,%s,0\n", \
1103 TARGET_64BIT ? "addi.d" : "addi.w", \
1104 reg_names[STACK_POINTER_REGNUM], \
1105 reg_names[STACK_POINTER_REGNUM], \
1106 TARGET_64BIT ? "st.d" : "st.w", reg_names[REGNO], \
1107 reg_names[STACK_POINTER_REGNUM]); \
1111 #define ASM_OUTPUT_REG_POP(STREAM, REGNO) \
1114 fprintf (STREAM, "\t%s\t%s,%s,0\n\t%s\t%s,%s,8\n", \
1115 TARGET_64BIT ? "ld.d" : "ld.w", reg_names[REGNO], \
1116 reg_names[STACK_POINTER_REGNUM], \
1117 TARGET_64BIT ? "addi.d" : "addi.w", \
1118 reg_names[STACK_POINTER_REGNUM], \
1119 reg_names[STACK_POINTER_REGNUM]); \
1123 /* How to start an assembler comment.
1124 The leading space is important (the loongarch native assembler requires it).
1126 #ifndef ASM_COMMENT_START
1127 #define ASM_COMMENT_START " #"
1131 #define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int")
1134 #define PTRDIFF_TYPE (POINTER_SIZE == 64 ? "long int" : "int")
1136 /* The maximum number of bytes that can be copied by one iteration of
1137 a cpymemsi loop; see loongarch_block_move_loop. */
1138 #define LARCH_MAX_MOVE_OPS_PER_LOOP_ITER 4
1140 /* The maximum number of bytes that can be copied by a straight-line
1141 implementation of cpymemsi; see loongarch_block_move_straight. We want
1142 to make sure that any loop-based implementation will iterate at
1144 #define LARCH_MAX_MOVE_OPS_STRAIGHT (LARCH_MAX_MOVE_OPS_PER_LOOP_ITER * 2)
1146 #define LARCH_MAX_MOVE_PER_INSN \
1147 (ISA_HAS_LASX ? 32 : (ISA_HAS_LSX ? 16 : UNITS_PER_WORD))
1149 /* The base cost of a memcpy call, for MOVE_RATIO and friends. These
1150 values were determined experimentally by benchmarking with CSiBE.
1152 #define LARCH_CALL_RATIO 6
1154 /* Any loop-based implementation of cpymemsi will have at least
1155 LARCH_MAX_MOVE_OPS_PER_LOOP_ITER memory-to-memory
1156 moves, so allow individual copies of fewer elements.
1158 When cpymemsi is not available, use a value approximating
1159 the length of a memcpy call sequence, so that move_by_pieces
1160 will generate inline code if it is shorter than a function call.
1161 Since move_by_pieces_ninsns counts memory-to-memory moves, but
1162 we'll have to generate a load/store pair for each, halve the
1163 value of LARCH_CALL_RATIO to take that into account. */
1165 #define MOVE_RATIO(speed) \
1166 (HAVE_cpymemsi ? LARCH_MAX_MOVE_OPS_PER_LOOP_ITER : CLEAR_RATIO (speed) / 2)
1168 /* For CLEAR_RATIO, when optimizing for size, give a better estimate
1169 of the length of a memset call, but use the default otherwise. */
1171 #define CLEAR_RATIO(speed) ((speed) ? 15 : LARCH_CALL_RATIO)
1173 /* This is similar to CLEAR_RATIO, but for a non-zero constant, so when
1174 optimizing for size adjust the ratio to account for the overhead of
1175 loading the constant and replicating it across the word. */
1177 #define SET_RATIO(speed) ((speed) ? 15 : LARCH_CALL_RATIO - 2)
1179 #ifndef USED_FOR_TARGET
1180 extern const enum reg_class loongarch_regno_to_class
[];
1181 extern int loongarch_dwarf_regno
[];
1183 /* Information about a function's frame layout. */
1184 struct GTY (()) loongarch_frame_info
1186 /* The size of the frame in bytes. */
1187 HOST_WIDE_INT total_size
;
1189 /* Bit X is set if the function saves or restores GPR X. */
1192 /* Likewise FPR X. */
1195 /* How much the GPR save/restore routines adjust sp (or 0 if unused). */
1196 unsigned save_libcall_adjustment
;
1198 /* Offsets of fixed-point and floating-point save areas from frame
1200 HOST_WIDE_INT gp_sp_offset
;
1201 HOST_WIDE_INT fp_sp_offset
;
1203 /* Offset of virtual frame pointer from stack pointer/frame bottom. */
1204 HOST_WIDE_INT frame_pointer_offset
;
1206 /* Offset of hard frame pointer from stack pointer/frame bottom. */
1207 HOST_WIDE_INT hard_frame_pointer_offset
;
1209 /* The offset of arg_pointer_rtx from the bottom of the frame. */
1210 HOST_WIDE_INT arg_pointer_offset
;
1213 struct GTY (()) machine_function
1215 /* The next floating-point condition-code register to allocate
1216 for 8CC targets, relative to FCC_REG_FIRST. */
1217 unsigned int next_fcc
;
1219 /* The number of extra stack bytes taken up by register varargs.
1220 This area is allocated by the callee at the very top of the frame. */
1223 /* The current frame information, calculated by loongarch_compute_frame_info.
1225 struct loongarch_frame_info frame
;
1227 bool reg_is_wrapped_separately
[FIRST_PSEUDO_REGISTER
];
1231 #ifdef HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT
1232 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
1233 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
1235 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
1236 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_absptr)
1239 /* Do emit .note.GNU-stack by default. */
1240 #ifndef NEED_INDICATE_EXEC_STACK
1241 #define NEED_INDICATE_EXEC_STACK 1
1244 /* The `Q' extension is not yet supported. */
1245 /* TODO: according to march. */
1246 #define UNITS_PER_FP_REG (TARGET_DOUBLE_FLOAT ? 8 : 4)
1248 /* The largest type that can be passed in floating-point registers. */
1249 /* TODO: according to mabi. */
1250 #define UNITS_PER_FP_ARG \
1251 (TARGET_HARD_FLOAT_ABI ? (TARGET_DOUBLE_FLOAT_ABI ? 8 : 4) : 0)
1253 #define FUNCTION_VALUE_REGNO_P(N) ((N) == GP_RETURN || (N) == FP_RETURN)
1255 /* LoongArch maintains ICache/DCache coherency by hardware,
1256 we just need "ibar" to avoid instruction hazard here. */
1257 #undef CLEAR_INSN_CACHE
1258 #define CLEAR_INSN_CACHE(beg, end) __builtin_loongarch_ibar (0)
1260 #define TARGET_EXPLICIT_RELOCS \
1261 (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)