]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/loongarch/loongarch-c.cc
1 /* LoongArch-specific code for C family languages.
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 #define IN_TARGET_CODE 1
25 #include "coretypes.h"
27 #include "c-family/c-common.h"
30 #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
31 #define builtin_define(TXT) cpp_define (pfile, TXT)
32 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
34 /* Define preprocessor macros for the -march and -mtune options.
35 PREFIX is either _LOONGARCH_ARCH or _LOONGARCH_TUNE, INFO is
36 the selected processor. If INFO's canonical name is "foo",
37 define PREFIX to be "foo", and define an additional macro
39 #define LARCH_CPP_SET_PROCESSOR(PREFIX, CPU_TYPE) \
43 int cpu_type = (CPU_TYPE); \
45 macro = concat ((PREFIX), "_", \
46 loongarch_cpu_strings[cpu_type], NULL); \
47 for (p = macro; *p != 0; p++) \
50 builtin_define (macro); \
51 builtin_define_with_value ((PREFIX), \
52 loongarch_cpu_strings[cpu_type], 1); \
58 loongarch_cpu_cpp_builtins (cpp_reader
*pfile
)
60 builtin_assert ("machine=loongarch");
61 builtin_assert ("cpu=loongarch");
62 builtin_define ("__loongarch__");
64 LARCH_CPP_SET_PROCESSOR ("_LOONGARCH_ARCH", la_target
.cpu_arch
);
65 LARCH_CPP_SET_PROCESSOR ("_LOONGARCH_TUNE", la_target
.cpu_tune
);
67 LARCH_CPP_SET_PROCESSOR ("__loongarch_arch", la_target
.cpu_arch
);
68 LARCH_CPP_SET_PROCESSOR ("__loongarch_tune", la_target
.cpu_tune
);
70 /* Base architecture / ABI. */
73 builtin_define ("__loongarch_grlen=64");
74 builtin_define ("__loongarch64");
79 builtin_define ("_ABILP64=3");
80 builtin_define ("_LOONGARCH_SIM=_ABILP64");
81 builtin_define ("__loongarch_lp64");
84 /* These defines reflect the ABI in use, not whether the
85 FPU is directly accessible. */
86 if (TARGET_DOUBLE_FLOAT_ABI
)
87 builtin_define ("__loongarch_double_float=1");
88 else if (TARGET_SINGLE_FLOAT_ABI
)
89 builtin_define ("__loongarch_single_float=1");
91 if (TARGET_DOUBLE_FLOAT_ABI
|| TARGET_SINGLE_FLOAT_ABI
)
92 builtin_define ("__loongarch_hard_float=1");
94 builtin_define ("__loongarch_soft_float=1");
98 if (TARGET_DOUBLE_FLOAT
)
99 builtin_define ("__loongarch_frlen=64");
100 else if (TARGET_SINGLE_FLOAT
)
101 builtin_define ("__loongarch_frlen=32");
103 builtin_define ("__loongarch_frlen=0");
105 if (TARGET_HARD_FLOAT
&& TARGET_FRECIPE
)
106 builtin_define ("__loongarch_frecipe");
110 builtin_define ("__loongarch_simd");
111 builtin_define ("__loongarch_sx");
114 builtin_define ("__loongarch_simd_width=128");
119 builtin_define ("__loongarch_asx");
120 builtin_define ("__loongarch_simd_width=256");
123 /* Add support for FLOAT128_TYPE on the LoongArch architecture. */
124 builtin_define ("__FLOAT128_TYPE__");
126 /* Map the old _Float128 'q' builtins into the new 'f128' builtins. */
127 builtin_define ("__builtin_fabsq=__builtin_fabsf128");
128 builtin_define ("__builtin_copysignq=__builtin_copysignf128");
129 builtin_define ("__builtin_nanq=__builtin_nanf128");
130 builtin_define ("__builtin_nansq=__builtin_nansf128");
131 builtin_define ("__builtin_infq=__builtin_inff128");
132 builtin_define ("__builtin_huge_valq=__builtin_huge_valf128");
134 /* Native Data Sizes. */
135 builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE
);
136 builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE
);
137 builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE
);
138 builtin_define_with_int_value ("_LOONGARCH_FPSET", 32);
139 builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);