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)
35 loongarch_cpu_cpp_builtins (cpp_reader
*pfile
)
37 builtin_assert ("machine=loongarch");
38 builtin_assert ("cpu=loongarch");
39 builtin_define ("__loongarch__");
41 builtin_define_with_value ("__loongarch_arch",
42 loongarch_arch_strings
[la_target
.cpu_arch
], 1);
44 builtin_define_with_value ("__loongarch_tune",
45 loongarch_tune_strings
[la_target
.cpu_tune
], 1);
47 builtin_define_with_value ("_LOONGARCH_ARCH",
48 loongarch_arch_strings
[la_target
.cpu_arch
], 1);
50 builtin_define_with_value ("_LOONGARCH_TUNE",
51 loongarch_tune_strings
[la_target
.cpu_tune
], 1);
53 /* Base architecture / ABI. */
56 builtin_define ("__loongarch_grlen=64");
57 builtin_define ("__loongarch64");
62 builtin_define ("_ABILP64=3");
63 builtin_define ("_LOONGARCH_SIM=_ABILP64");
64 builtin_define ("__loongarch_lp64");
67 /* These defines reflect the ABI in use, not whether the
68 FPU is directly accessible. */
69 if (TARGET_DOUBLE_FLOAT_ABI
)
70 builtin_define ("__loongarch_double_float=1");
71 else if (TARGET_SINGLE_FLOAT_ABI
)
72 builtin_define ("__loongarch_single_float=1");
74 if (TARGET_DOUBLE_FLOAT_ABI
|| TARGET_SINGLE_FLOAT_ABI
)
75 builtin_define ("__loongarch_hard_float=1");
77 builtin_define ("__loongarch_soft_float=1");
81 if (TARGET_DOUBLE_FLOAT
)
82 builtin_define ("__loongarch_frlen=64");
83 else if (TARGET_SINGLE_FLOAT
)
84 builtin_define ("__loongarch_frlen=32");
86 builtin_define ("__loongarch_frlen=0");
88 if (TARGET_HARD_FLOAT
&& ISA_HAS_FRECIPE
)
89 builtin_define ("__loongarch_frecipe");
93 builtin_define ("__loongarch_simd");
94 builtin_define ("__loongarch_sx");
97 builtin_define ("__loongarch_simd_width=128");
102 builtin_define ("__loongarch_asx");
103 builtin_define ("__loongarch_simd_width=256");
106 /* ISA evolution features */
107 int max_v_major
= 1, max_v_minor
= 0;
109 for (int i
= 0; i
< N_EVO_FEATURES
; i
++)
110 if (la_target
.isa
.evolution
& la_evo_feature_masks
[i
])
112 builtin_define (la_evo_macro_name
[i
]);
114 int major
= la_evo_version_major
[i
],
115 minor
= la_evo_version_minor
[i
];
117 max_v_major
= major
> max_v_major
? major
: max_v_major
;
118 max_v_minor
= major
== max_v_major
119 ? (minor
> max_v_minor
? minor
: max_v_minor
): max_v_minor
;
122 /* Find the minimum ISA version required to run the target program. */
123 if (!(max_v_major
== 1 && max_v_minor
<= 1 && ISA_HAS_LASX
))
125 builtin_define_with_int_value ("__loongarch_version_major", max_v_major
);
126 builtin_define_with_int_value ("__loongarch_version_minor", max_v_minor
);
129 /* Add support for FLOAT128_TYPE on the LoongArch architecture. */
130 builtin_define ("__FLOAT128_TYPE__");
132 /* Map the old _Float128 'q' builtins into the new 'f128' builtins. */
133 builtin_define ("__builtin_fabsq=__builtin_fabsf128");
134 builtin_define ("__builtin_copysignq=__builtin_copysignf128");
135 builtin_define ("__builtin_nanq=__builtin_nanf128");
136 builtin_define ("__builtin_nansq=__builtin_nansf128");
137 builtin_define ("__builtin_infq=__builtin_inff128");
138 builtin_define ("__builtin_huge_valq=__builtin_huge_valf128");
140 /* Native Data Sizes. */
141 builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE
);
142 builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE
);
143 builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE
);
144 builtin_define_with_int_value ("_LOONGARCH_FPSET", 32);
145 builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);