|
23 | 23 | // and modified by Doris |
24 | 24 | #pragma once |
25 | 25 |
|
26 | | -#include <boost/math/special_functions/fpclassify.hpp> |
27 | 26 | #include <cassert> |
28 | 27 | #include <cfloat> |
29 | 28 | #include <cmath> |
|
37 | 36 |
|
38 | 37 | /// Use same extended double for all platforms |
39 | 38 | #if (LDBL_MANT_DIG == 64) |
| 39 | +#include <boost/math/special_functions/fpclassify.hpp> |
| 40 | + |
40 | 41 | #define CONSTEXPR_FROM_DOUBLE constexpr |
| 42 | +#define DORIS_WIDE_FROM_DOUBLE_INLINE 1 |
41 | 43 | using FromDoubleIntermediateType = long double; |
42 | | -#else |
| 44 | +#elif defined(DORIS_WIDE_INTEGER_FROM_DOUBLE_IMPL_TU) |
| 45 | +#include <boost/math/special_functions/fpclassify.hpp> |
43 | 46 | #include <boost/multiprecision/cpp_bin_float.hpp> |
44 | 47 | /// `wide_integer_from_builtin` can't be constexpr with non-literal `cpp_bin_float_double_extended` |
45 | 48 | #define CONSTEXPR_FROM_DOUBLE |
| 49 | +#define DORIS_WIDE_FROM_DOUBLE_INLINE 1 |
46 | 50 | using FromDoubleIntermediateType = boost::multiprecision::cpp_bin_float_double_extended; |
| 51 | +#else |
| 52 | +/// Platforms without an 80-bit long double emulate the intermediate type with |
| 53 | +/// boost::multiprecision, which drags ~4.3MB of preprocessed closure into every |
| 54 | +/// TU. Ordinary TUs therefore see only declarations of the two from-double |
| 55 | +/// members below; the bodies are compiled once in |
| 56 | +/// core/wide_integer_from_double.cpp (which defines the *_IMPL_TU macro above |
| 57 | +/// and emits explicit instantiations). wide_integer_from_builtin(double) was |
| 58 | +/// never constexpr on these platforms, so no constant evaluation is lost. |
| 59 | +#define CONSTEXPR_FROM_DOUBLE |
| 60 | +#define DORIS_WIDE_FROM_DOUBLE_INLINE 0 |
47 | 61 | #endif |
48 | 62 |
|
49 | 63 | namespace wide { |
@@ -308,7 +322,11 @@ struct integer<Bits, Signed>::_impl { |
308 | 322 | * a_(n - 1) = a_n * max_int + b2, a_n <= max_int <- base case. |
309 | 323 | */ |
310 | 324 | template <class T> |
311 | | - constexpr static void set_multiplier(integer<Bits, Signed>& self, T t) noexcept { |
| 325 | + CONSTEXPR_FROM_DOUBLE static void set_multiplier(integer<Bits, Signed>& self, T t) noexcept |
| 326 | +#if !DORIS_WIDE_FROM_DOUBLE_INLINE |
| 327 | + ; |
| 328 | +#else |
| 329 | + { |
312 | 330 | constexpr uint64_t max_int = std::numeric_limits<uint64_t>::max(); |
313 | 331 | static_assert(std::is_same_v<T, double> || std::is_same_v<T, FromDoubleIntermediateType>); |
314 | 332 | /// Implementation specific behaviour on overflow (if we don't check here, stack overflow will triggered in bigint_cast). |
@@ -343,9 +361,14 @@ struct integer<Bits, Signed>::_impl { |
343 | 361 | self += static_cast<uint64_t>(t - floor(static_cast<double>(alpha)) * |
344 | 362 | static_cast<T>(max_int)); // += b_i |
345 | 363 | } |
| 364 | +#endif |
346 | 365 |
|
347 | 366 | CONSTEXPR_FROM_DOUBLE static void wide_integer_from_builtin(integer<Bits, Signed>& self, |
348 | | - double rhs) noexcept { |
| 367 | + double rhs) noexcept |
| 368 | +#if !DORIS_WIDE_FROM_DOUBLE_INLINE |
| 369 | + ; |
| 370 | +#else |
| 371 | + { |
349 | 372 | constexpr int64_t max_int = std::numeric_limits<int64_t>::max(); |
350 | 373 | constexpr int64_t min_int = std::numeric_limits<int64_t>::lowest(); |
351 | 374 |
|
@@ -374,6 +397,7 @@ struct integer<Bits, Signed>::_impl { |
374 | 397 | self = -self; |
375 | 398 | } |
376 | 399 | } |
| 400 | +#endif |
377 | 401 |
|
378 | 402 | template <size_t Bits2, typename Signed2> |
379 | 403 | constexpr static void wide_integer_from_wide_integer( |
|
0 commit comments