|
12 | 12 | #include "tools.h"
|
13 | 13 | #include "flang/Common/float128.h"
|
14 | 14 | #include "flang/Runtime/entry-names.h"
|
| 15 | +#include <cfloat> |
15 | 16 | #include <type_traits>
|
16 | 17 |
|
17 | 18 | namespace Fortran::runtime {
|
@@ -42,7 +43,8 @@ namespace Fortran::runtime {
|
42 | 43 | #define DEFINE_SIMPLE_ALIAS(caller, callee) \
|
43 | 44 | template <typename RT, typename... ATs, RT (*p)(ATs...)> struct caller<p> { \
|
44 | 45 | static RT invoke(ATs... args) { \
|
45 |
| - static_assert(std::is_invocable_r_v<RT, decltype(callee), ATs...>); \ |
| 46 | + static_assert(std::is_invocable_r_v<RT, \ |
| 47 | + decltype(callee(std::declval<ATs>()...))(ATs...), ATs...>); \ |
46 | 48 | if constexpr (std::is_same_v<RT, void>) { \
|
47 | 49 | callee(args...); \
|
48 | 50 | } else { \
|
@@ -98,7 +100,69 @@ typedef _Complex float __attribute__((mode(TC))) ComplexF128;
|
98 | 100 | typedef _Complex float __attribute__((mode(KC))) ComplexF128;
|
99 | 101 | #endif
|
100 | 102 |
|
101 |
| -#if HAS_QUADMATHLIB |
| 103 | +#if HAS_LIBM |
| 104 | +// Define wrapper callers for libm. |
| 105 | +#include <ccomplex> |
| 106 | +#include <cmath> |
| 107 | + |
| 108 | +#if LDBL_MANT_DIG == 113 |
| 109 | +// Use STD math functions. They provide IEEE-754 128-bit float |
| 110 | +// support either via 'long double' or __float128. |
| 111 | +// The Bessel's functions are not present in STD namespace. |
| 112 | +DEFINE_SIMPLE_ALIAS(Acos, std::acos) |
| 113 | +DEFINE_SIMPLE_ALIAS(Acosh, std::acosh) |
| 114 | +DEFINE_SIMPLE_ALIAS(Asin, std::asin) |
| 115 | +DEFINE_SIMPLE_ALIAS(Asinh, std::asinh) |
| 116 | +DEFINE_SIMPLE_ALIAS(Atan, std::atan) |
| 117 | +DEFINE_SIMPLE_ALIAS(Atan2, std::atan2) |
| 118 | +DEFINE_SIMPLE_ALIAS(Atanh, std::atanh) |
| 119 | +// TODO: enable complex abs, when ABI adjustment for complex |
| 120 | +// data type is resolved. |
| 121 | +// DEFINE_SIMPLE_ALIAS(CAbs, std::abs) |
| 122 | +DEFINE_SIMPLE_ALIAS(Ceil, std::ceil) |
| 123 | +DEFINE_SIMPLE_ALIAS(Cos, std::cos) |
| 124 | +DEFINE_SIMPLE_ALIAS(Cosh, std::cosh) |
| 125 | +DEFINE_SIMPLE_ALIAS(Erf, std::erf) |
| 126 | +DEFINE_SIMPLE_ALIAS(Erfc, std::erfc) |
| 127 | +DEFINE_SIMPLE_ALIAS(Exp, std::exp) |
| 128 | +DEFINE_SIMPLE_ALIAS(Floor, std::floor) |
| 129 | +DEFINE_SIMPLE_ALIAS(Hypot, std::hypot) |
| 130 | +DEFINE_SIMPLE_ALIAS(J0, j0l) |
| 131 | +DEFINE_SIMPLE_ALIAS(J1, j1l) |
| 132 | +DEFINE_SIMPLE_ALIAS(Jn, jnl) |
| 133 | +DEFINE_SIMPLE_ALIAS(Lgamma, std::lgamma) |
| 134 | +DEFINE_SIMPLE_ALIAS(Llround, std::llround) |
| 135 | +DEFINE_SIMPLE_ALIAS(Lround, std::lround) |
| 136 | +DEFINE_SIMPLE_ALIAS(Log, std::log) |
| 137 | +DEFINE_SIMPLE_ALIAS(Log10, std::log10) |
| 138 | +DEFINE_SIMPLE_ALIAS(Pow, std::pow) |
| 139 | +DEFINE_SIMPLE_ALIAS(Round, std::round) |
| 140 | +DEFINE_SIMPLE_ALIAS(Sin, std::sin) |
| 141 | +DEFINE_SIMPLE_ALIAS(Sinh, std::sinh) |
| 142 | +DEFINE_SIMPLE_ALIAS(Sqrt, std::sqrt) |
| 143 | +DEFINE_SIMPLE_ALIAS(Tan, std::tan) |
| 144 | +DEFINE_SIMPLE_ALIAS(Tanh, std::tanh) |
| 145 | +DEFINE_SIMPLE_ALIAS(Tgamma, std::tgamma) |
| 146 | +DEFINE_SIMPLE_ALIAS(Trunc, std::trunc) |
| 147 | +DEFINE_SIMPLE_ALIAS(Y0, y0l) |
| 148 | +DEFINE_SIMPLE_ALIAS(Y1, y1l) |
| 149 | +DEFINE_SIMPLE_ALIAS(Yn, ynl) |
| 150 | +#else // LDBL_MANT_DIG != 113 |
| 151 | +#if !HAS_LIBMF128 |
| 152 | +// glibc >=2.26 seems to have complete support for __float128 |
| 153 | +// versions of the math functions. |
| 154 | +#error "FLANG_RUNTIME_F128_MATH_LIB=libm build requires libm >=2.26" |
| 155 | +#endif |
| 156 | + |
| 157 | +// We can use __float128 versions of libm functions. |
| 158 | +// __STDC_WANT_IEC_60559_TYPES_EXT__ needs to be defined |
| 159 | +// before including cmath to enable the *f128 prototypes. |
| 160 | +// TODO: this needs to be enabled separately, especially |
| 161 | +// for complex data types that require C++ complex to C complex |
| 162 | +// adjustment to match the ABIs. |
| 163 | +#error "Unsupported FLANG_RUNTIME_F128_MATH_LIB=libm build" |
| 164 | +#endif // LDBL_MANT_DIG != 113 |
| 165 | +#elif HAS_QUADMATHLIB |
102 | 166 | // Define wrapper callers for libquadmath.
|
103 | 167 | #include "quadmath.h"
|
104 | 168 | DEFINE_SIMPLE_ALIAS(Acos, acosq)
|
|
0 commit comments