xref: /netbsd-src/external/gpl3/gcc/dist/gcc/config/loongarch/loongarch-c.cc (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1 /* LoongArch-specific code for C family languages.
2    Copyright (C) 2021-2022 Free Software Foundation, Inc.
3    Contributed by Loongson Ltd.
4 
5 This file is part of GCC.
6 
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)
10 any later version.
11 
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.
16 
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/>.  */
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 
57 void
loongarch_cpu_cpp_builtins(cpp_reader * pfile)58 loongarch_cpu_cpp_builtins (cpp_reader *pfile)
59 {
60   builtin_assert ("machine=loongarch");
61   builtin_assert ("cpu=loongarch");
62   builtin_define ("__loongarch__");
63 
64   LARCH_CPP_SET_PROCESSOR ("_LOONGARCH_ARCH", LARCH_ACTUAL_ARCH);
65   LARCH_CPP_SET_PROCESSOR ("_LOONGARCH_TUNE", LARCH_ACTUAL_TUNE);
66 
67   /* Base architecture / ABI.  */
68   if (TARGET_64BIT)
69     {
70       builtin_define ("__loongarch_grlen=64");
71       builtin_define ("__loongarch64");
72     }
73 
74   if (TARGET_ABI_LP64)
75     {
76       builtin_define ("_ABILP64=3");
77       builtin_define ("_LOONGARCH_SIM=_ABILP64");
78       builtin_define ("__loongarch_lp64");
79     }
80 
81   /* These defines reflect the ABI in use, not whether the
82      FPU is directly accessible.  */
83   if (TARGET_DOUBLE_FLOAT_ABI)
84     builtin_define ("__loongarch_double_float=1");
85   else if (TARGET_SINGLE_FLOAT_ABI)
86     builtin_define ("__loongarch_single_float=1");
87 
88   if (TARGET_DOUBLE_FLOAT_ABI || TARGET_SINGLE_FLOAT_ABI)
89     builtin_define ("__loongarch_hard_float=1");
90   else
91     builtin_define ("__loongarch_soft_float=1");
92 
93 
94   /* ISA Extensions.  */
95   if (TARGET_DOUBLE_FLOAT)
96     builtin_define ("__loongarch_frlen=64");
97   else if (TARGET_SINGLE_FLOAT)
98     builtin_define ("__loongarch_frlen=32");
99   else
100     builtin_define ("__loongarch_frlen=0");
101 
102   /* Native Data Sizes.  */
103   builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE);
104   builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE);
105   builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE);
106   builtin_define_with_int_value ("_LOONGARCH_FPSET", 32);
107   builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);
108 
109 }
110