]>
Commit | Line | Data |
---|---|---|
09cae750 | 1 | /* RISC-V-specific code for C family languages. |
7adcbafe | 2 | Copyright (C) 2011-2022 Free Software Foundation, Inc. |
09cae750 PD |
3 | Contributed by Andrew Waterman (andrew@sifive.com). |
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 | ||
8fcc61f8 RS |
21 | #define IN_TARGET_CODE 1 |
22 | ||
e3354b6d | 23 | #define INCLUDE_STRING |
09cae750 PD |
24 | #include "config.h" |
25 | #include "system.h" | |
26 | #include "coretypes.h" | |
27 | #include "tm.h" | |
28 | #include "c-family/c-common.h" | |
29 | #include "cpplib.h" | |
e3354b6d | 30 | #include "riscv-subset.h" |
09cae750 PD |
31 | |
32 | #define builtin_define(TXT) cpp_define (pfile, TXT) | |
33 | ||
34 | /* Implement TARGET_CPU_CPP_BUILTINS. */ | |
35 | ||
36 | void | |
37 | riscv_cpu_cpp_builtins (cpp_reader *pfile) | |
38 | { | |
39 | builtin_define ("__riscv"); | |
119b4963 | 40 | |
09cae750 PD |
41 | if (TARGET_RVC) |
42 | builtin_define ("__riscv_compressed"); | |
119b4963 | 43 | |
09baee1a KC |
44 | if (TARGET_RVE) |
45 | builtin_define ("__riscv_32e"); | |
46 | ||
09cae750 PD |
47 | if (TARGET_ATOMIC) |
48 | builtin_define ("__riscv_atomic"); | |
119b4963 | 49 | |
09cae750 PD |
50 | if (TARGET_MUL) |
51 | builtin_define ("__riscv_mul"); | |
52 | if (TARGET_DIV) | |
53 | builtin_define ("__riscv_div"); | |
54 | if (TARGET_DIV && TARGET_MUL) | |
55 | builtin_define ("__riscv_muldiv"); | |
119b4963 | 56 | |
09cae750 PD |
57 | builtin_define_with_int_value ("__riscv_xlen", UNITS_PER_WORD * 8); |
58 | if (TARGET_HARD_FLOAT) | |
59 | builtin_define_with_int_value ("__riscv_flen", UNITS_PER_FP_REG * 8); | |
119b4963 | 60 | |
09cae750 PD |
61 | if (TARGET_HARD_FLOAT && TARGET_FDIV) |
62 | { | |
63 | builtin_define ("__riscv_fdiv"); | |
64 | builtin_define ("__riscv_fsqrt"); | |
65 | } | |
119b4963 | 66 | |
09cae750 PD |
67 | switch (riscv_abi) |
68 | { | |
09baee1a | 69 | case ABI_ILP32E: |
119b4963 JW |
70 | builtin_define ("__riscv_abi_rve"); |
71 | gcc_fallthrough (); | |
72 | ||
73 | case ABI_ILP32: | |
09cae750 PD |
74 | case ABI_LP64: |
75 | builtin_define ("__riscv_float_abi_soft"); | |
76 | break; | |
119b4963 | 77 | |
09cae750 PD |
78 | case ABI_ILP32F: |
79 | case ABI_LP64F: | |
80 | builtin_define ("__riscv_float_abi_single"); | |
81 | break; | |
119b4963 | 82 | |
09cae750 PD |
83 | case ABI_ILP32D: |
84 | case ABI_LP64D: | |
85 | builtin_define ("__riscv_float_abi_double"); | |
86 | break; | |
87 | } | |
119b4963 | 88 | |
09cae750 PD |
89 | switch (riscv_cmodel) |
90 | { | |
91 | case CM_MEDLOW: | |
92 | builtin_define ("__riscv_cmodel_medlow"); | |
93 | break; | |
119b4963 | 94 | |
30784833 KC |
95 | case CM_PIC: |
96 | /* __riscv_cmodel_pic is deprecated, and will removed in next GCC release. | |
97 | see https://github.com/riscv/riscv-c-api-doc/pull/11 */ | |
98 | builtin_define ("__riscv_cmodel_pic"); | |
99 | /* FALLTHROUGH. */ | |
100 | ||
09cae750 PD |
101 | case CM_MEDANY: |
102 | builtin_define ("__riscv_cmodel_medany"); | |
103 | break; | |
119b4963 | 104 | |
09cae750 | 105 | } |
e3354b6d KC |
106 | |
107 | /* Define architecture extension test macros. */ | |
108 | builtin_define_with_int_value ("__riscv_arch_test", 1); | |
109 | ||
110 | const riscv_subset_list *subset_list = riscv_current_subset_list (); | |
111 | size_t max_ext_len = 0; | |
112 | ||
113 | /* Figure out the max length of extension name for reserving buffer. */ | |
114 | for (const riscv_subset_t *subset = subset_list->begin (); | |
115 | subset != subset_list->end (); | |
116 | subset = subset->next) | |
117 | max_ext_len = MAX (max_ext_len, subset->name.length ()); | |
118 | ||
119 | char *buf = (char *)alloca (max_ext_len + 10 /* For __riscv_ and '\0'. */); | |
120 | ||
121 | for (const riscv_subset_t *subset = subset_list->begin (); | |
122 | subset != subset_list->end (); | |
123 | subset = subset->next) | |
124 | { | |
125 | int version_value = (subset->major_version * 1000000) | |
126 | + (subset->minor_version * 1000); | |
127 | /* Special rule for zicsr and zifencei, it's used for ISA spec 2.2 or | |
128 | earlier. */ | |
129 | if ((subset->name == "zicsr" || subset->name == "zifencei") | |
130 | && version_value == 0) | |
131 | version_value = 2000000; | |
132 | ||
133 | sprintf (buf, "__riscv_%s", subset->name.c_str ()); | |
134 | builtin_define_with_int_value (buf, version_value); | |
135 | } | |
09cae750 | 136 | } |