[flang-commits] [flang] [flang][runtime] Use fallback bessel functions when not available in libm (PR #101437)
Daniel Martinez via flang-commits
flang-commits at lists.llvm.org
Wed Jul 31 18:07:57 PDT 2024
https://github.com/Calandracas606 created https://github.com/llvm/llvm-project/pull/101437
Fixes compilation on linux when using musl as the libc.
musl does not provide long double variants of the bessel functions.
>From 8a0c2301664e7178b2c48a8cfb2a10151bdde462 Mon Sep 17 00:00:00 2001
From: Daniel Martinez <danielmartinez at cock.li>
Date: Wed, 31 Jul 2024 14:28:29 -0400
Subject: [PATCH] [flang][runtime] Use fallback bessel functions on musl
Fixes compilation on linux when using musl as the libc.
musl does not provide long double variants of the bessel functions.
---
flang/runtime/Float128Math/CMakeLists.txt | 20 ++++++++++++++++++++
flang/runtime/Float128Math/math-entries.h | 4 ++++
2 files changed, 24 insertions(+)
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index a5f5bec1e7e4b..b7d890df1f4aa 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -108,6 +108,26 @@ elseif (HAVE_LDBL_MANT_DIG_113)
# We can use 'long double' versions from libc.
check_library_exists(m sinl "" FOUND_LIBM)
if (FOUND_LIBM)
+ check_cxx_source_compiles(
+ "#include <cmath>
+ int main() {
+ int n = 0;
+ long double x = 1;
+ long double Y0 = y0l(x);
+ long double Y1 = y1l(x);
+ long double Yn = ynl(n,x);
+ long double J0 = j0l(x);
+ long double J1 = j1l(x);
+ long double Jn = jnl(n,x);
+ return 0;
+ }
+ "
+ FOUND_LIBM_BESSEL)
+ if (FOUND_LIBM_BESSEL)
+ target_compile_definitions(FortranFloat128MathILib INTERFACE
+ HAS_LIBM_BESSEL
+ )
+ endif()
target_compile_definitions(FortranFloat128MathILib INTERFACE
HAS_LIBM
)
diff --git a/flang/runtime/Float128Math/math-entries.h b/flang/runtime/Float128Math/math-entries.h
index 13fdab2647003..45ae40fdafa0e 100644
--- a/flang/runtime/Float128Math/math-entries.h
+++ b/flang/runtime/Float128Math/math-entries.h
@@ -185,9 +185,11 @@ DEFINE_SIMPLE_ALIAS(Hypot, std::hypot)
DEFINE_SIMPLE_ALIAS(Ilogb, std::ilogb)
DEFINE_SIMPLE_ALIAS(Isinf, std::isinf)
DEFINE_SIMPLE_ALIAS(Isnan, std::isnan)
+#ifdef HAS_LIBM_BESSEL
DEFINE_SIMPLE_ALIAS(J0, j0l)
DEFINE_SIMPLE_ALIAS(J1, j1l)
DEFINE_SIMPLE_ALIAS(Jn, jnl)
+#endif
DEFINE_SIMPLE_ALIAS(Ldexp, std::ldexp)
DEFINE_SIMPLE_ALIAS(Lgamma, std::lgamma)
DEFINE_SIMPLE_ALIAS(Llround, std::llround)
@@ -204,9 +206,11 @@ DEFINE_SIMPLE_ALIAS(Tan, std::tan)
DEFINE_SIMPLE_ALIAS(Tanh, std::tanh)
DEFINE_SIMPLE_ALIAS(Tgamma, std::tgamma)
DEFINE_SIMPLE_ALIAS(Trunc, std::trunc)
+#ifdef HAS_LIBM_BESSEL
DEFINE_SIMPLE_ALIAS(Y0, y0l)
DEFINE_SIMPLE_ALIAS(Y1, y1l)
DEFINE_SIMPLE_ALIAS(Yn, ynl)
+#endif
// Use numeric_limits to produce infinity of the right type.
#define F128_RT_INFINITY \
More information about the flang-commits
mailing list