]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/loongarch/loongarch-c.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / config / loongarch / loongarch-c.cc
CommitLineData
7e60c24c 1/* LoongArch-specific code for C family languages.
a945c346 2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
7e60c24c 3 Contributed by Loongson Ltd.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#define IN_TARGET_CODE 1
22
23#include "config.h"
24#include "system.h"
25#include "coretypes.h"
26#include "tm.h"
27#include "c-family/c-common.h"
28#include "cpplib.h"
29
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)
33
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
38 PREFIX_FOO. */
39#define LARCH_CPP_SET_PROCESSOR(PREFIX, CPU_TYPE) \
40 do \
41 { \
42 char *macro, *p; \
43 int cpu_type = (CPU_TYPE); \
44 \
45 macro = concat ((PREFIX), "_", \
46 loongarch_cpu_strings[cpu_type], NULL); \
47 for (p = macro; *p != 0; p++) \
48 *p = TOUPPER (*p); \
49 \
50 builtin_define (macro); \
51 builtin_define_with_value ((PREFIX), \
52 loongarch_cpu_strings[cpu_type], 1); \
53 free (macro); \
54 } \
55 while (0)
56
57void
58loongarch_cpu_cpp_builtins (cpp_reader *pfile)
59{
60 builtin_assert ("machine=loongarch");
61 builtin_assert ("cpu=loongarch");
62 builtin_define ("__loongarch__");
63
bb4a8198
YY
64 LARCH_CPP_SET_PROCESSOR ("_LOONGARCH_ARCH", la_target.cpu_arch);
65 LARCH_CPP_SET_PROCESSOR ("_LOONGARCH_TUNE", la_target.cpu_tune);
7e60c24c 66
f095da2c
YY
67 LARCH_CPP_SET_PROCESSOR ("__loongarch_arch", la_target.cpu_arch);
68 LARCH_CPP_SET_PROCESSOR ("__loongarch_tune", la_target.cpu_tune);
69
7e60c24c 70 /* Base architecture / ABI. */
71 if (TARGET_64BIT)
72 {
73 builtin_define ("__loongarch_grlen=64");
74 builtin_define ("__loongarch64");
75 }
76
77 if (TARGET_ABI_LP64)
78 {
79 builtin_define ("_ABILP64=3");
80 builtin_define ("_LOONGARCH_SIM=_ABILP64");
81 builtin_define ("__loongarch_lp64");
82 }
83
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");
90
91 if (TARGET_DOUBLE_FLOAT_ABI || TARGET_SINGLE_FLOAT_ABI)
92 builtin_define ("__loongarch_hard_float=1");
93 else
94 builtin_define ("__loongarch_soft_float=1");
95
96
97 /* ISA Extensions. */
98 if (TARGET_DOUBLE_FLOAT)
99 builtin_define ("__loongarch_frlen=64");
100 else if (TARGET_SINGLE_FLOAT)
101 builtin_define ("__loongarch_frlen=32");
102 else
103 builtin_define ("__loongarch_frlen=0");
104
61f1001f
JX
105 if (TARGET_HARD_FLOAT && TARGET_FRECIPE)
106 builtin_define ("__loongarch_frecipe");
107
bb4a8198
YY
108 if (ISA_HAS_LSX)
109 {
110 builtin_define ("__loongarch_simd");
111 builtin_define ("__loongarch_sx");
112
113 if (!ISA_HAS_LASX)
114 builtin_define ("__loongarch_simd_width=128");
115 }
116
117 if (ISA_HAS_LASX)
118 {
119 builtin_define ("__loongarch_asx");
120 builtin_define ("__loongarch_simd_width=256");
121 }
122
4e2d53c9 123 /* Add support for FLOAT128_TYPE on the LoongArch architecture. */
124 builtin_define ("__FLOAT128_TYPE__");
125
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");
133
7e60c24c 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);
140
141}