-
Notifications
You must be signed in to change notification settings - Fork 26
/
config.hpp.in
288 lines (197 loc) · 7.61 KB
/
config.hpp.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Copyright 2016-2023 Francesco Biscani (bluescarni@gmail.com)
//
// This file is part of the mp++ library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef MPPP_CONFIG_HPP
#define MPPP_CONFIG_HPP
// Start of defines instantiated by CMake.
// clang-format off
#define MPPP_VERSION_STRING "@mp++_VERSION@"
#define MPPP_VERSION_MAJOR @mp++_VERSION_MAJOR@
#define MPPP_VERSION_MINOR @mp++_VERSION_MINOR@
#define MPPP_VERSION_PATCH @mp++_VERSION_PATCH@
#define MPPP_ABI_VERSION @MPPP_ABI_VERSION@
#cmakedefine MPPP_GMP_HAVE_MPN_DIVEXACT_1
@MPPP_ENABLE_MPFR@
#cmakedefine MPPP_MPFR_HAVE_MPFR_GET_Q
#cmakedefine MPPP_MPFR_HAVE_MPFR_ROOTN_UI
#cmakedefine MPPP_MPFR_HAVE_MPFR_GAMMA_INC
#cmakedefine MPPP_MPFR_HAVE_MPFR_BETA
#cmakedefine MPPP_MPFR_HAVE_MPFR_ROUNDEVEN
#cmakedefine MPPP_MPFR_HAVE_MPFR_FMODQUO
#cmakedefine MPPP_MPFR_HAVE_MPFR_GET_STR_NDIGITS
@MPPP_ENABLE_ARB@
#cmakedefine MPPP_ARB_HAVE_ACB_AGM
@MPPP_ENABLE_MPC@
@MPPP_ENABLE_QUADMATH@
#cmakedefine MPPP_QUADMATH_HAVE_EXP2Q
#cmakedefine MPPP_QUADMATH_HAVE_LOGBQ
@MPPP_STATIC_BUILD@
#cmakedefine MPPP_WITH_BOOST_S11N
#cmakedefine MPPP_WITH_FMT
// clang-format on
// End of defines instantiated by CMake.
// Setup of the ABI versioning and tagging
// machinery.
#if defined(__GNUC__) || defined(__clang__)
#define MPPP_ABI_TAG_ATTR __attribute__((abi_tag))
#else
#define MPPP_ABI_TAG_ATTR
#endif
// clang-format off
#define MPPP_BEGIN_NAMESPACE \
namespace mppp \
{ \
inline namespace v@MPPP_ABI_VERSION@ MPPP_ABI_TAG_ATTR \
{
#define MPPP_END_NAMESPACE \
} \
}
// clang-format on
// Compiler configuration.
#if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER)
// NOTE: GCC, clang (including clang-cl) and the Intel compiler support
// __builtin_expect() and __restrict.
#define mppp_likely(x) __builtin_expect(static_cast<bool>(x), 1)
#define mppp_unlikely(x) __builtin_expect(static_cast<bool>(x), 0)
#define MPPP_RESTRICT __restrict
#elif defined(_MSC_VER)
// NOTE: MSVC (without clang-cl) only supports __restrict.
#define mppp_likely(x) (x)
#define mppp_unlikely(x) (x)
#define MPPP_RESTRICT __restrict
#else
// Otherwise, disable both __builtin_expect() and __restrict.
#define mppp_likely(x) (x)
#define mppp_unlikely(x) (x)
#define MPPP_RESTRICT
#endif
// thread_local configuration:
// - on clang/osx, this seems to be supported since xcode 8:
// https://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports
// Note that additional conditions might be needed for iOS, if it ever comes
// to that. Regarding the versioning, it seems the clang version macros are set
// to the xcode version:
// https://stackoverflow.com/questions/19387043/how-can-i-reliably-detect-the-version-of-clang-at-preprocessing-time
// xcode 8.x is appleclang 8.y:
// https://en.wikipedia.org/wiki/Xcode#8.x_series
// - at least some MinGW versions have a buggy thread_local implementation. This is shown by testing,
// and reported in a bunch of places as well:
// https://sourceforge.net/p/mingw-w64/bugs/445/
// https://github.com/Alexpux/MINGW-packages/issues/2519
//
// NOTE: at least some early versions of the Intel compiler have a buggy implementation,
// but recent versions seem ok.
#if (defined(__APPLE__) && __clang_major__ < 8) || defined(__MINGW32__)
#define MPPP_MAYBE_TLS
#else
// For the rest, we assume thread_local is available.
#define MPPP_MAYBE_TLS static thread_local
#define MPPP_HAVE_THREAD_LOCAL
#endif
// Concepts setup.
#if defined(__cpp_concepts)
#define MPPP_HAVE_CONCEPTS
// NOTE: GCC < 9 uses the syntax of the concept TS.
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9
#define MPPP_CONCEPT_DECL concept bool
#else
#define MPPP_CONCEPT_DECL concept
#endif
#endif
// C++ standard setup.
// NOTE: this is necessary because at this time MSVC does not set correctly the
// __cplusplus macro.
#if defined(_MSC_VER)
#define MPPP_CPLUSPLUS _MSVC_LANG
#else
#define MPPP_CPLUSPLUS __cplusplus
#endif
// constexpr setup.
#if MPPP_CPLUSPLUS >= 201402L
#define MPPP_CONSTEXPR_14 constexpr
#else
#define MPPP_CONSTEXPR_14
#endif
#if MPPP_CPLUSPLUS >= 202002L
#define MPPP_CONSTEXPR_20 constexpr
#else
#define MPPP_CONSTEXPR_20
#endif
// Detect if the compiler supports GCC-style 128-bit integers.
// NOTE: we can check int128 on GCC/clang with __SIZEOF_INT128__ apparently:
// http://stackoverflow.com/questions/21886985/what-gcc-versions-support-the-int128-intrinsic-type
// NOTE: clang-cl supports the types, but not all the arithmetic operations on them. Let's disable it for now.
#if ((defined(__clang__) && !defined(_MSC_VER)) || defined(__GNUC__) || defined(__INTEL_COMPILER)) \
&& defined(__SIZEOF_INT128__)
#define MPPP_HAVE_GCC_INT128
#endif
// Check if we have std::string_view available.
// Older compilers might advertise C++17 support
// without implementing all the necessary library
// components - this is the case with MSVC 2015
// and std::string_view.
#if MPPP_CPLUSPLUS >= 201703L
#if __has_include(<string_view>)
#define MPPP_HAVE_STRING_VIEW
#endif
#endif
// Wrapper for the C++17 [[fallthrough]] attribute.
#if MPPP_CPLUSPLUS >= 201703L
#define MPPP_FALLTHROUGH [[fallthrough]]
#elif !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 7
// On GCC>=7, if we are not using C++17 we can use
// an alternative attribute:
// https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
// This may be supported on some clang versions as well:
// https://reviews.llvm.org/D63260
#define MPPP_FALLTHROUGH [[gnu::fallthrough]]
#else
#define MPPP_FALLTHROUGH void(0)
#endif
// Wrapper for the C++17 [[nodiscard]], [[maybe_unused]] attributes.
#if MPPP_CPLUSPLUS >= 201703L
#define MPPP_NODISCARD [[nodiscard]]
#define MPPP_MAYBE_UNUSED [[maybe_unused]]
#else
#define MPPP_NODISCARD
#define MPPP_MAYBE_UNUSED
#endif
// C++20 constinit.
// NOTE: this seems to be buggy currently on MSVC:
// https://github.com/bluescarni/mppp/issues/291
#if defined(__cpp_constinit) && (!defined(_MSC_VER) || defined(__clang__))
#define MPPP_CONSTINIT constinit
#else
#define MPPP_CONSTINIT
#endif
#if defined(MPPP_WITH_QUADMATH)
// Define the MPPP_FLOAT128_WITH_LONG_DOUBLE name
// if __float128 can interact with long double.
#if defined(__clang__)
#if defined(__apple_build_version__)
// NOTE: according to https://en.wikipedia.org/wiki/Xcode#Toolchain_versions,
// clang 7 starts in Xcode 10.2.
#if __clang_major__ > 10 || (__clang_major__ == 10 && __clang_minor__ >= 2)
#define MPPP_FLOAT128_WITH_LONG_DOUBLE
#endif
#else
// Vanilla clang.
#if __clang_major__ >= 7
#define MPPP_FLOAT128_WITH_LONG_DOUBLE
#endif
#endif
#else
// On non-clang, let's always assume that __float128
// can interact with long double, *unless* we are on
// PowerPC. On such a setup, GCC disables interaction
// between __float128 and long double.
#if !defined(__PPC__)
#define MPPP_FLOAT128_WITH_LONG_DOUBLE
#endif
#endif
#endif
#endif