Skip to content

[flang][runtime] Disable LDBL_MANT_DIG == 113 for the offload builds. #109339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

vzakhari
Copy link
Contributor

When compiling on aarch64 some LDBL_MANT_DIG == 113 entries
end up trying to use complex<long double> for which there are
no certain specializations in libcudacxx. This change-set
includes a clean-up for LDBL_MANT_DIG == 113 usage, which is replaced
with HAS_LDBL128 that is set in float128.h.

When compiling on aarch64 some `LDBL_MANT_DIG == 113` entries
end up trying to use `complex<long double>` for which there are
no certain specializations in `libcudacxx`. This change-set
includes a clean-up for `LDBL_MANT_DIG == 113` usage, which is replaced
with `HAS_LDBL128` that is set in `float128.h`.
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Sep 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2024

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-flang-semantics

Author: Slava Zakharin (vzakhari)

Changes

When compiling on aarch64 some LDBL_MANT_DIG == 113 entries
end up trying to use complex&lt;long double&gt; for which there are
no certain specializations in libcudacxx. This change-set
includes a clean-up for LDBL_MANT_DIG == 113 usage, which is replaced
with HAS_LDBL128 that is set in float128.h.


Patch is 62.98 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/109339.diff

75 Files Affected:

  • (modified) flang/include/flang/Common/float128.h (+14-1)
  • (modified) flang/include/flang/Runtime/cpp-type.h (+2-2)
  • (modified) flang/include/flang/Runtime/matmul-instances.inc (+3-3)
  • (modified) flang/include/flang/Runtime/numeric.h (+16-16)
  • (modified) flang/include/flang/Runtime/reduce.h (+2-2)
  • (modified) flang/include/flang/Runtime/reduction.h (+9-9)
  • (modified) flang/include/flang/Runtime/transformational.h (+4-4)
  • (modified) flang/include/flang/Tools/TargetSetup.h (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+4-3)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/acos.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/acosh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/asin.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/asinh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/atan.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/atan2.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/atanh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/ceil.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/complex-math.c (+2-2)
  • (modified) flang/runtime/Float128Math/complex-math.h (+1-1)
  • (modified) flang/runtime/Float128Math/cos.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/cosh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/erf.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/erfc.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/exp.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/exponent.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/floor.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/fma.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/fraction.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/hypot.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/j0.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/j1.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/jn.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/lgamma.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/llround.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/log.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/log10.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/lround.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/math-entries.h (+1-1)
  • (modified) flang/runtime/Float128Math/mod-real.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/modulo-real.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/nearest.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/norm2.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/pow.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/random.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/round.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/rrspacing.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/scale.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/set-exponent.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/sin.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/sinh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/spacing.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/sqrt.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/tan.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/tanh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/tgamma.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/trunc.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/y0.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/y1.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/yn.cpp (+1-1)
  • (modified) flang/runtime/complex-powi.cpp (+3-3)
  • (modified) flang/runtime/complex-reduction.c (+6-6)
  • (modified) flang/runtime/complex-reduction.h (+5-5)
  • (modified) flang/runtime/dot-product.cpp (+2-2)
  • (modified) flang/runtime/extrema.cpp (+4-4)
  • (modified) flang/runtime/numeric-templates.h (+1-1)
  • (modified) flang/runtime/numeric.cpp (+8-8)
  • (modified) flang/runtime/product.cpp (+2-2)
  • (modified) flang/runtime/reduce.cpp (+2-2)
  • (modified) flang/runtime/reduction-templates.h (+3-3)
  • (modified) flang/runtime/sum.cpp (+2-2)
  • (modified) flang/runtime/transformational.cpp (+4-4)
  • (modified) flang/unittests/Runtime/Numeric.cpp (+1-1)
  • (modified) flang/unittests/Runtime/Reduction.cpp (+2-2)
  • (modified) flang/unittests/Runtime/Transformational.cpp (+4-4)
diff --git a/flang/include/flang/Common/float128.h b/flang/include/flang/Common/float128.h
index 2e76bc0a162e61..eddd3cf25382e1 100644
--- a/flang/include/flang/Common/float128.h
+++ b/flang/include/flang/Common/float128.h
@@ -20,6 +20,7 @@
 #ifndef FORTRAN_COMMON_FLOAT128_H_
 #define FORTRAN_COMMON_FLOAT128_H_
 
+#include "api-attrs.h"
 #include <float.h>
 
 #ifdef __cplusplus
@@ -51,8 +52,20 @@
 #endif /* (defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) && \
           !defined(_LIBCPP_VERSION)  && !defined(__CUDA_ARCH__) */
 
-/* Define pure C CFloat128Type and CFloat128ComplexType. */
 #if LDBL_MANT_DIG == 113
+#define HAS_LDBL128 1
+#endif
+
+#if defined(RT_DEVICE_COMPILATION) && defined(__CUDACC__)
+/*
+ * Most offload targets do not support 128-bit 'long double'.
+ * Disable HAS_LDBL128 for __CUDACC__ for the time being.
+ */
+#undef HAS_LDBL128
+#endif
+
+/* Define pure C CFloat128Type and CFloat128ComplexType. */
+#if HAS_LDBL128
 typedef long double CFloat128Type;
 #ifndef __cplusplus
 typedef long double _Complex CFloat128ComplexType;
diff --git a/flang/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h
index aef0fbd7ede586..f6180b4a9ab60c 100644
--- a/flang/include/flang/Runtime/cpp-type.h
+++ b/flang/include/flang/Runtime/cpp-type.h
@@ -78,12 +78,12 @@ template <> struct CppTypeForHelper<TypeCategory::Real, 10> {
 #endif
 #if __STDCPP_FLOAT128_T__
 using CppFloat128Type = std::float128_t;
-#elif LDBL_MANT_DIG == 113
+#elif HAS_LDBL128
 using CppFloat128Type = long double;
 #elif HAS_FLOAT128
 using CppFloat128Type = __float128;
 #endif
-#if __STDCPP_FLOAT128_t || LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if __STDCPP_FLOAT128_t || HAS_LDBL128 || HAS_FLOAT128
 template <> struct CppTypeForHelper<TypeCategory::Real, 16> {
   using type = CppFloat128Type;
 };
diff --git a/flang/include/flang/Runtime/matmul-instances.inc b/flang/include/flang/Runtime/matmul-instances.inc
index 88e3067ca029d4..da319481fce3b8 100644
--- a/flang/include/flang/Runtime/matmul-instances.inc
+++ b/flang/include/flang/Runtime/matmul-instances.inc
@@ -121,7 +121,7 @@ MATMUL_DIRECT_INSTANCE(Integer, 16, Complex, 10)
 MATMUL_DIRECT_INSTANCE(Real, 10, Integer, 16)
 MATMUL_DIRECT_INSTANCE(Complex, 10, Integer, 16)
 #endif
-#if MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128)
+#if MATMUL_FORCE_ALL_TYPES || (HAS_LDBL128 || HAS_FLOAT128)
 MATMUL_INSTANCE(Integer, 16, Real, 16)
 MATMUL_INSTANCE(Integer, 16, Complex, 16)
 MATMUL_INSTANCE(Real, 16, Integer, 16)
@@ -195,7 +195,7 @@ MATMUL_DIRECT_INSTANCE(Complex, 16, Complex, 10)
 #endif
 #endif // MATMUL_FORCE_ALL_TYPES || HAS_FLOAT80
 
-#if MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128)
+#if MATMUL_FORCE_ALL_TYPES || (HAS_LDBL128 || HAS_FLOAT128)
 #define FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(macro)         \
   macro(Integer, 1, Real, 16)                               \
   macro(Integer, 1, Complex, 16)                            \
@@ -236,7 +236,7 @@ MATMUL_DIRECT_INSTANCE(Complex, 16, Complex, 10)
 
 FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(MATMUL_INSTANCE)
 FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(MATMUL_DIRECT_INSTANCE)
-#endif // MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128)
+#endif // MATMUL_FORCE_ALL_TYPES || (HAS_LDBL128 || HAS_FLOAT128)
 
 #define FOREACH_MATMUL_LOGICAL_TYPE_PAIR(macro) \
   macro(Logical, 1, Logical, 1)                 \
diff --git a/flang/include/flang/Runtime/numeric.h b/flang/include/flang/Runtime/numeric.h
index c3923ee2e0d889..9e6bf357861e75 100644
--- a/flang/include/flang/Runtime/numeric.h
+++ b/flang/include/flang/Runtime/numeric.h
@@ -58,7 +58,7 @@ CppTypeFor<TypeCategory::Integer, 16> RTDECL(Ceiling10_16)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Integer, 1> RTDECL(Ceiling16_1)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 2> RTDECL(Ceiling16_2)(
@@ -82,7 +82,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(ErfcScaled8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(ErfcScaled10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(ErfcScaled16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -102,7 +102,7 @@ CppTypeFor<TypeCategory::Integer, 4> RTDECL(Exponent10_4)(
 CppTypeFor<TypeCategory::Integer, 8> RTDECL(Exponent10_8)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT
+#if HAS_LDBL128 || HAS_FLOAT
 CppTypeFor<TypeCategory::Integer, 4> RTDECL(Exponent16_4)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 8> RTDECL(Exponent16_8)(
@@ -148,7 +148,7 @@ CppTypeFor<TypeCategory::Integer, 16> RTDECL(Floor10_16)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Integer, 1> RTDECL(Floor16_1)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 2> RTDECL(Floor16_2)(
@@ -172,7 +172,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Fraction8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Fraction10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Fraction16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -183,7 +183,7 @@ bool RTDECL(IsNaN8)(CppTypeFor<TypeCategory::Real, 8>);
 #if HAS_FLOAT80
 bool RTDECL(IsNaN10)(CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 bool RTDECL(IsNaN16)(CppTypeFor<TypeCategory::Real, 16>);
 #endif
 
@@ -217,7 +217,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(ModReal10)(
     CppTypeFor<TypeCategory::Real, 10>, CppTypeFor<TypeCategory::Real, 10>,
     const char *sourceFile = nullptr, int sourceLine = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(ModReal16)(
     CppTypeFor<TypeCategory::Real, 16>, CppTypeFor<TypeCategory::Real, 16>,
     const char *sourceFile = nullptr, int sourceLine = 0);
@@ -252,7 +252,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(ModuloReal10)(
     CppTypeFor<TypeCategory::Real, 10>, CppTypeFor<TypeCategory::Real, 10>,
     const char *sourceFile = nullptr, int sourceLine = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(ModuloReal16)(
     CppTypeFor<TypeCategory::Real, 16>, CppTypeFor<TypeCategory::Real, 16>,
     const char *sourceFile = nullptr, int sourceLine = 0);
@@ -297,7 +297,7 @@ CppTypeFor<TypeCategory::Integer, 16> RTDECL(Nint10_16)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Integer, 1> RTDECL(Nint16_1)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 2> RTDECL(Nint16_2)(
@@ -323,7 +323,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Nearest8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Nearest10)(
     CppTypeFor<TypeCategory::Real, 10>, bool positive);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Nearest16)(
     CppTypeFor<TypeCategory::Real, 16>, bool positive);
 #endif
@@ -337,7 +337,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(RRSpacing8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(RRSpacing10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(RRSpacing16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -351,7 +351,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(SetExponent8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(SetExponent10)(
     CppTypeFor<TypeCategory::Real, 10>, std::int64_t);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(SetExponent16)(
     CppTypeFor<TypeCategory::Real, 16>, std::int64_t);
 #endif
@@ -365,7 +365,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Scale8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Scale10)(
     CppTypeFor<TypeCategory::Real, 10>, std::int64_t);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Scale16)(
     CppTypeFor<TypeCategory::Real, 16>, std::int64_t);
 #endif
@@ -414,7 +414,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Spacing8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Spacing10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Spacing16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -430,7 +430,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(FPow10i)(
     CppTypeFor<TypeCategory::Real, 10> b,
     CppTypeFor<TypeCategory::Integer, 4> e);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16i)(
     CppTypeFor<TypeCategory::Real, 16> b,
     CppTypeFor<TypeCategory::Integer, 4> e);
@@ -447,7 +447,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(FPow10k)(
     CppTypeFor<TypeCategory::Real, 10> b,
     CppTypeFor<TypeCategory::Integer, 8> e);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16k)(
     CppTypeFor<TypeCategory::Real, 16> b,
     CppTypeFor<TypeCategory::Integer, 8> e);
diff --git a/flang/include/flang/Runtime/reduce.h b/flang/include/flang/Runtime/reduce.h
index c016b37f9592a1..c63782b85f22f5 100644
--- a/flang/include/flang/Runtime/reduce.h
+++ b/flang/include/flang/Runtime/reduce.h
@@ -210,7 +210,7 @@ void RTDECL(ReduceReal10DimValue)(Descriptor &result, const Descriptor &array,
     const CppTypeFor<TypeCategory::Real, 10> *identity = nullptr,
     bool ordered = true);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(ReduceReal16Ref)(const Descriptor &,
     ReferenceReductionOperation<CppFloat128Type>, const char *source, int line,
     int dim = 0, const Descriptor *mask = nullptr,
@@ -351,7 +351,7 @@ void RTDECL(CppReduceComplex10DimValue)(Descriptor &result,
     const CppTypeFor<TypeCategory::Complex, 10> *identity = nullptr,
     bool ordered = true);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppReduceComplex16Ref)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &,
     ReferenceReductionOperation<CppTypeFor<TypeCategory::Complex, 16>>,
diff --git a/flang/include/flang/Runtime/reduction.h b/flang/include/flang/Runtime/reduction.h
index 7eafacee69d034..91811581f645d5 100644
--- a/flang/include/flang/Runtime/reduction.h
+++ b/flang/include/flang/Runtime/reduction.h
@@ -73,7 +73,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(SumReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(SumReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -95,7 +95,7 @@ void RTDECL(CppSumComplex10)(CppTypeFor<TypeCategory::Complex, 10> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppSumComplex16)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
@@ -134,7 +134,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(ProductReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(ProductReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -156,7 +156,7 @@ void RTDECL(CppProductComplex10)(CppTypeFor<TypeCategory::Complex, 10> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppProductComplex16)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
@@ -314,7 +314,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(MaxvalReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(MaxvalReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -346,7 +346,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(MinvalReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(MinvalReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -371,7 +371,7 @@ double RTDECL(Norm2_8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Norm2_10)(
     const Descriptor &, const char *source, int line, int dim = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(Norm2_16)(
     const Descriptor &, const char *source, int line, int dim = 0);
 void RTDECL(Norm2DimReal16)(
@@ -421,7 +421,7 @@ double RTDECL(DotProductReal8)(const Descriptor &, const Descriptor &,
 CppTypeFor<TypeCategory::Real, 10> RTDECL(DotProductReal10)(const Descriptor &,
     const Descriptor &, const char *source = nullptr, int line = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(DotProductReal16)(const Descriptor &, const Descriptor &,
     const char *source = nullptr, int line = 0);
 #endif
@@ -442,7 +442,7 @@ void RTDECL(CppDotProductComplex10)(CppTypeFor<TypeCategory::Complex, 10> &,
     const Descriptor &, const Descriptor &, const char *source = nullptr,
     int line = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppDotProductComplex16)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &, const Descriptor &, const char *source = nullptr,
     int line = 0);
diff --git a/flang/include/flang/Runtime/transformational.h b/flang/include/flang/Runtime/transformational.h
index faeaa1baa39ae2..d04fa685978837 100644
--- a/flang/include/flang/Runtime/transformational.h
+++ b/flang/include/flang/Runtime/transformational.h
@@ -53,7 +53,7 @@ void RTDECL(BesselJn_10)(Descriptor &result, int32_t n1, int32_t n2,
     int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselJn_16)(Descriptor &result, int32_t n1, int32_t n2,
     CppFloat128Type x, CppFloat128Type bn2, CppFloat128Type bn2_1,
     const char *sourceFile = nullptr, int line = 0);
@@ -76,7 +76,7 @@ void RTDECL(BesselJnX0_10)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselJnX0_16)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
@@ -101,7 +101,7 @@ void RTDECL(BesselYn_10)(Descriptor &result, int32_t n1, int32_t n2,
     int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselYn_16)(Descriptor &result, int32_t n1, int32_t n2,
     CppFloat128Type x, CppFloat128Type bn1, CppFloat128Type bn1_1,
     const char *sourceFile = nullptr, int line = 0);
@@ -124,7 +124,7 @@ void RTDECL(BesselYnX0_10)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselYnX0_16)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
diff --git a/flang/include/flang/Tools/TargetSetup.h b/flang/include/flang/Tools/TargetSetup.h
index ee89249441c174..d6d36835bd2cb3 100644
--- a/flang/include/flang/Tools/TargetSetup.h
+++ b/flang/include/flang/Tools/TargetSetup.h
@@ -36,7 +36,7 @@ namespace Fortran::tools {
 #ifdef FLANG_RUNTIME_F128_MATH_LIB
   // we can use libquadmath wrappers
   constexpr bool f128Support = true;
-#elif LDBL_MANT_DIG == 113
+#elif HAS_LDBL128
   // we can use libm wrappers
   constexpr bool f128Support = true;
 #else
diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index ed28d8130808fa..ce9dd6b7b3df86 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -22,8 +22,9 @@
 #include <functional>
 #if HAS_QUADMATHLIB
 #include "quadmath.h"
-#include "flang/Common/float128.h"
 #endif
+#include "flang/Common/float128.h"
+#include "flang/Common/float80.h"
 #include <type_traits>
 
 namespace Fortran::evaluate {
@@ -414,7 +415,7 @@ template <> struct HostRuntimeLibrary<double, LibraryVersion::LibmExtensions> {
   static_assert(map.Verify(), "map must be sorted");
 };
 
-#if LDBL_MANT_DIG == 80 || LDBL_MANT_DIG == 113
+#if HAS_FLOAT80 || HAS_LDBL128
 template <>
 struct HostRuntimeLibrary<long double, LibraryVersion::LibmExtensions> {
   using F = FuncPointer<long double, long double>;
@@ -430,7 +431,7 @@ struct HostRuntimeLibrary<long double, LibraryVersion::LibmExtensions> {
   static constexpr HostRuntimeMap map{table};
   static_assert(map.Verify(), "map must be sorted");
 };
-#endif // LDBL_MANT_DIG == 80 || LDBL_MANT_DIG == 113
+#endif // HAS_FLOAT80 || HAS_LDBL128
 #endif //_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
 
 /// Define pgmath description
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index dc0dc47bda9a9d..4e6d92213c1241 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -750,7 +750,7 @@ prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
 
 // Generate a call to the Fortran runtime library providing
 // support for 128-bit float math.
-// On 'LDBL_MANT_DIG == 113' targets the implementation
+// On 'HAS_LDBL128' targets the implementation
 // is provided by FortranRuntime, otherwise, it is done via
 // FortranFloat128Math library. In the latter case the compiler
 // has to be built with FLANG_RUNTIME_F128_MATH_LIB to guarantee
diff --git a/flang/runtime/Float128Math/acos.cpp b/flang/runtime/Float128Math/acos.cpp
index 14ff6944856844..d9b4950aa1e35c 100644
--- a/flang/runtime/Float128Math/acos.cpp
+++ b/flang/runtime/Float128Math/acos.cpp
@@ -11,7 +11,7 @@
 namespace Fortran::runtime {
 extern "C" {
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDEF(AcosF128)(
     CppTypeFor<TypeCategory::Real, 16> x) {
   return Acos<true>::invoke(x);
diff --git a/flang/runtime/Float128Math/acosh.cpp b/flang/runtime/Float128Math/acosh.cpp
index 9d70804e44a470..c572673ef55e62 100644
--- a/flang/runtime/Float128Math/acosh.cpp
+++ b/flang/runtime/Float128Math/acosh.cpp
@@ -11,7 +11,7 @@
 namespace Fortran::runtime {
 extern "C" {
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDEF(AcoshF128)(
     CppTypeFor<TypeCategory::Real, 16> x) {
   return Acosh<true>::invoke(x);
diff --git a/flang/runtime/Float128Math/asin.cpp b/flang/runtime/Float128Math/asin.cpp
index 6781b23f0363db..57b6ffd9673605 100644
--- a/flang/runtime/Float128Math/asin.cpp
+++ b/flang/ru...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2024

@llvm/pr-subscribers-flang-runtime

Author: Slava Zakharin (vzakhari)

Changes

When compiling on aarch64 some LDBL_MANT_DIG == 113 entries
end up trying to use complex&lt;long double&gt; for which there are
no certain specializations in libcudacxx. This change-set
includes a clean-up for LDBL_MANT_DIG == 113 usage, which is replaced
with HAS_LDBL128 that is set in float128.h.


Patch is 62.98 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/109339.diff

75 Files Affected:

  • (modified) flang/include/flang/Common/float128.h (+14-1)
  • (modified) flang/include/flang/Runtime/cpp-type.h (+2-2)
  • (modified) flang/include/flang/Runtime/matmul-instances.inc (+3-3)
  • (modified) flang/include/flang/Runtime/numeric.h (+16-16)
  • (modified) flang/include/flang/Runtime/reduce.h (+2-2)
  • (modified) flang/include/flang/Runtime/reduction.h (+9-9)
  • (modified) flang/include/flang/Runtime/transformational.h (+4-4)
  • (modified) flang/include/flang/Tools/TargetSetup.h (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+4-3)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/acos.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/acosh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/asin.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/asinh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/atan.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/atan2.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/atanh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/ceil.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/complex-math.c (+2-2)
  • (modified) flang/runtime/Float128Math/complex-math.h (+1-1)
  • (modified) flang/runtime/Float128Math/cos.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/cosh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/erf.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/erfc.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/exp.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/exponent.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/floor.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/fma.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/fraction.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/hypot.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/j0.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/j1.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/jn.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/lgamma.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/llround.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/log.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/log10.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/lround.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/math-entries.h (+1-1)
  • (modified) flang/runtime/Float128Math/mod-real.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/modulo-real.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/nearest.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/norm2.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/pow.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/random.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/round.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/rrspacing.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/scale.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/set-exponent.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/sin.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/sinh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/spacing.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/sqrt.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/tan.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/tanh.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/tgamma.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/trunc.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/y0.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/y1.cpp (+1-1)
  • (modified) flang/runtime/Float128Math/yn.cpp (+1-1)
  • (modified) flang/runtime/complex-powi.cpp (+3-3)
  • (modified) flang/runtime/complex-reduction.c (+6-6)
  • (modified) flang/runtime/complex-reduction.h (+5-5)
  • (modified) flang/runtime/dot-product.cpp (+2-2)
  • (modified) flang/runtime/extrema.cpp (+4-4)
  • (modified) flang/runtime/numeric-templates.h (+1-1)
  • (modified) flang/runtime/numeric.cpp (+8-8)
  • (modified) flang/runtime/product.cpp (+2-2)
  • (modified) flang/runtime/reduce.cpp (+2-2)
  • (modified) flang/runtime/reduction-templates.h (+3-3)
  • (modified) flang/runtime/sum.cpp (+2-2)
  • (modified) flang/runtime/transformational.cpp (+4-4)
  • (modified) flang/unittests/Runtime/Numeric.cpp (+1-1)
  • (modified) flang/unittests/Runtime/Reduction.cpp (+2-2)
  • (modified) flang/unittests/Runtime/Transformational.cpp (+4-4)
diff --git a/flang/include/flang/Common/float128.h b/flang/include/flang/Common/float128.h
index 2e76bc0a162e61..eddd3cf25382e1 100644
--- a/flang/include/flang/Common/float128.h
+++ b/flang/include/flang/Common/float128.h
@@ -20,6 +20,7 @@
 #ifndef FORTRAN_COMMON_FLOAT128_H_
 #define FORTRAN_COMMON_FLOAT128_H_
 
+#include "api-attrs.h"
 #include <float.h>
 
 #ifdef __cplusplus
@@ -51,8 +52,20 @@
 #endif /* (defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) && \
           !defined(_LIBCPP_VERSION)  && !defined(__CUDA_ARCH__) */
 
-/* Define pure C CFloat128Type and CFloat128ComplexType. */
 #if LDBL_MANT_DIG == 113
+#define HAS_LDBL128 1
+#endif
+
+#if defined(RT_DEVICE_COMPILATION) && defined(__CUDACC__)
+/*
+ * Most offload targets do not support 128-bit 'long double'.
+ * Disable HAS_LDBL128 for __CUDACC__ for the time being.
+ */
+#undef HAS_LDBL128
+#endif
+
+/* Define pure C CFloat128Type and CFloat128ComplexType. */
+#if HAS_LDBL128
 typedef long double CFloat128Type;
 #ifndef __cplusplus
 typedef long double _Complex CFloat128ComplexType;
diff --git a/flang/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h
index aef0fbd7ede586..f6180b4a9ab60c 100644
--- a/flang/include/flang/Runtime/cpp-type.h
+++ b/flang/include/flang/Runtime/cpp-type.h
@@ -78,12 +78,12 @@ template <> struct CppTypeForHelper<TypeCategory::Real, 10> {
 #endif
 #if __STDCPP_FLOAT128_T__
 using CppFloat128Type = std::float128_t;
-#elif LDBL_MANT_DIG == 113
+#elif HAS_LDBL128
 using CppFloat128Type = long double;
 #elif HAS_FLOAT128
 using CppFloat128Type = __float128;
 #endif
-#if __STDCPP_FLOAT128_t || LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if __STDCPP_FLOAT128_t || HAS_LDBL128 || HAS_FLOAT128
 template <> struct CppTypeForHelper<TypeCategory::Real, 16> {
   using type = CppFloat128Type;
 };
diff --git a/flang/include/flang/Runtime/matmul-instances.inc b/flang/include/flang/Runtime/matmul-instances.inc
index 88e3067ca029d4..da319481fce3b8 100644
--- a/flang/include/flang/Runtime/matmul-instances.inc
+++ b/flang/include/flang/Runtime/matmul-instances.inc
@@ -121,7 +121,7 @@ MATMUL_DIRECT_INSTANCE(Integer, 16, Complex, 10)
 MATMUL_DIRECT_INSTANCE(Real, 10, Integer, 16)
 MATMUL_DIRECT_INSTANCE(Complex, 10, Integer, 16)
 #endif
-#if MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128)
+#if MATMUL_FORCE_ALL_TYPES || (HAS_LDBL128 || HAS_FLOAT128)
 MATMUL_INSTANCE(Integer, 16, Real, 16)
 MATMUL_INSTANCE(Integer, 16, Complex, 16)
 MATMUL_INSTANCE(Real, 16, Integer, 16)
@@ -195,7 +195,7 @@ MATMUL_DIRECT_INSTANCE(Complex, 16, Complex, 10)
 #endif
 #endif // MATMUL_FORCE_ALL_TYPES || HAS_FLOAT80
 
-#if MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128)
+#if MATMUL_FORCE_ALL_TYPES || (HAS_LDBL128 || HAS_FLOAT128)
 #define FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(macro)         \
   macro(Integer, 1, Real, 16)                               \
   macro(Integer, 1, Complex, 16)                            \
@@ -236,7 +236,7 @@ MATMUL_DIRECT_INSTANCE(Complex, 16, Complex, 10)
 
 FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(MATMUL_INSTANCE)
 FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(MATMUL_DIRECT_INSTANCE)
-#endif // MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128)
+#endif // MATMUL_FORCE_ALL_TYPES || (HAS_LDBL128 || HAS_FLOAT128)
 
 #define FOREACH_MATMUL_LOGICAL_TYPE_PAIR(macro) \
   macro(Logical, 1, Logical, 1)                 \
diff --git a/flang/include/flang/Runtime/numeric.h b/flang/include/flang/Runtime/numeric.h
index c3923ee2e0d889..9e6bf357861e75 100644
--- a/flang/include/flang/Runtime/numeric.h
+++ b/flang/include/flang/Runtime/numeric.h
@@ -58,7 +58,7 @@ CppTypeFor<TypeCategory::Integer, 16> RTDECL(Ceiling10_16)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Integer, 1> RTDECL(Ceiling16_1)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 2> RTDECL(Ceiling16_2)(
@@ -82,7 +82,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(ErfcScaled8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(ErfcScaled10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(ErfcScaled16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -102,7 +102,7 @@ CppTypeFor<TypeCategory::Integer, 4> RTDECL(Exponent10_4)(
 CppTypeFor<TypeCategory::Integer, 8> RTDECL(Exponent10_8)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT
+#if HAS_LDBL128 || HAS_FLOAT
 CppTypeFor<TypeCategory::Integer, 4> RTDECL(Exponent16_4)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 8> RTDECL(Exponent16_8)(
@@ -148,7 +148,7 @@ CppTypeFor<TypeCategory::Integer, 16> RTDECL(Floor10_16)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Integer, 1> RTDECL(Floor16_1)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 2> RTDECL(Floor16_2)(
@@ -172,7 +172,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Fraction8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Fraction10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Fraction16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -183,7 +183,7 @@ bool RTDECL(IsNaN8)(CppTypeFor<TypeCategory::Real, 8>);
 #if HAS_FLOAT80
 bool RTDECL(IsNaN10)(CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 bool RTDECL(IsNaN16)(CppTypeFor<TypeCategory::Real, 16>);
 #endif
 
@@ -217,7 +217,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(ModReal10)(
     CppTypeFor<TypeCategory::Real, 10>, CppTypeFor<TypeCategory::Real, 10>,
     const char *sourceFile = nullptr, int sourceLine = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(ModReal16)(
     CppTypeFor<TypeCategory::Real, 16>, CppTypeFor<TypeCategory::Real, 16>,
     const char *sourceFile = nullptr, int sourceLine = 0);
@@ -252,7 +252,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(ModuloReal10)(
     CppTypeFor<TypeCategory::Real, 10>, CppTypeFor<TypeCategory::Real, 10>,
     const char *sourceFile = nullptr, int sourceLine = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(ModuloReal16)(
     CppTypeFor<TypeCategory::Real, 16>, CppTypeFor<TypeCategory::Real, 16>,
     const char *sourceFile = nullptr, int sourceLine = 0);
@@ -297,7 +297,7 @@ CppTypeFor<TypeCategory::Integer, 16> RTDECL(Nint10_16)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Integer, 1> RTDECL(Nint16_1)(
     CppTypeFor<TypeCategory::Real, 16>);
 CppTypeFor<TypeCategory::Integer, 2> RTDECL(Nint16_2)(
@@ -323,7 +323,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Nearest8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Nearest10)(
     CppTypeFor<TypeCategory::Real, 10>, bool positive);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Nearest16)(
     CppTypeFor<TypeCategory::Real, 16>, bool positive);
 #endif
@@ -337,7 +337,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(RRSpacing8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(RRSpacing10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(RRSpacing16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -351,7 +351,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(SetExponent8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(SetExponent10)(
     CppTypeFor<TypeCategory::Real, 10>, std::int64_t);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(SetExponent16)(
     CppTypeFor<TypeCategory::Real, 16>, std::int64_t);
 #endif
@@ -365,7 +365,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Scale8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Scale10)(
     CppTypeFor<TypeCategory::Real, 10>, std::int64_t);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Scale16)(
     CppTypeFor<TypeCategory::Real, 16>, std::int64_t);
 #endif
@@ -414,7 +414,7 @@ CppTypeFor<TypeCategory::Real, 8> RTDECL(Spacing8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Spacing10)(
     CppTypeFor<TypeCategory::Real, 10>);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(Spacing16)(
     CppTypeFor<TypeCategory::Real, 16>);
 #endif
@@ -430,7 +430,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(FPow10i)(
     CppTypeFor<TypeCategory::Real, 10> b,
     CppTypeFor<TypeCategory::Integer, 4> e);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16i)(
     CppTypeFor<TypeCategory::Real, 16> b,
     CppTypeFor<TypeCategory::Integer, 4> e);
@@ -447,7 +447,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(FPow10k)(
     CppTypeFor<TypeCategory::Real, 10> b,
     CppTypeFor<TypeCategory::Integer, 8> e);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16k)(
     CppTypeFor<TypeCategory::Real, 16> b,
     CppTypeFor<TypeCategory::Integer, 8> e);
diff --git a/flang/include/flang/Runtime/reduce.h b/flang/include/flang/Runtime/reduce.h
index c016b37f9592a1..c63782b85f22f5 100644
--- a/flang/include/flang/Runtime/reduce.h
+++ b/flang/include/flang/Runtime/reduce.h
@@ -210,7 +210,7 @@ void RTDECL(ReduceReal10DimValue)(Descriptor &result, const Descriptor &array,
     const CppTypeFor<TypeCategory::Real, 10> *identity = nullptr,
     bool ordered = true);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(ReduceReal16Ref)(const Descriptor &,
     ReferenceReductionOperation<CppFloat128Type>, const char *source, int line,
     int dim = 0, const Descriptor *mask = nullptr,
@@ -351,7 +351,7 @@ void RTDECL(CppReduceComplex10DimValue)(Descriptor &result,
     const CppTypeFor<TypeCategory::Complex, 10> *identity = nullptr,
     bool ordered = true);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppReduceComplex16Ref)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &,
     ReferenceReductionOperation<CppTypeFor<TypeCategory::Complex, 16>>,
diff --git a/flang/include/flang/Runtime/reduction.h b/flang/include/flang/Runtime/reduction.h
index 7eafacee69d034..91811581f645d5 100644
--- a/flang/include/flang/Runtime/reduction.h
+++ b/flang/include/flang/Runtime/reduction.h
@@ -73,7 +73,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(SumReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(SumReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -95,7 +95,7 @@ void RTDECL(CppSumComplex10)(CppTypeFor<TypeCategory::Complex, 10> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppSumComplex16)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
@@ -134,7 +134,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(ProductReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(ProductReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -156,7 +156,7 @@ void RTDECL(CppProductComplex10)(CppTypeFor<TypeCategory::Complex, 10> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppProductComplex16)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &, const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
@@ -314,7 +314,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(MaxvalReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(MaxvalReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -346,7 +346,7 @@ CppTypeFor<TypeCategory::Real, 10> RTDECL(MinvalReal10)(const Descriptor &,
     const char *source, int line, int dim = 0,
     const Descriptor *mask = nullptr);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(MinvalReal16)(const Descriptor &, const char *source,
     int line, int dim = 0, const Descriptor *mask = nullptr);
 #endif
@@ -371,7 +371,7 @@ double RTDECL(Norm2_8)(
 CppTypeFor<TypeCategory::Real, 10> RTDECL(Norm2_10)(
     const Descriptor &, const char *source, int line, int dim = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(Norm2_16)(
     const Descriptor &, const char *source, int line, int dim = 0);
 void RTDECL(Norm2DimReal16)(
@@ -421,7 +421,7 @@ double RTDECL(DotProductReal8)(const Descriptor &, const Descriptor &,
 CppTypeFor<TypeCategory::Real, 10> RTDECL(DotProductReal10)(const Descriptor &,
     const Descriptor &, const char *source = nullptr, int line = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppFloat128Type RTDECL(DotProductReal16)(const Descriptor &, const Descriptor &,
     const char *source = nullptr, int line = 0);
 #endif
@@ -442,7 +442,7 @@ void RTDECL(CppDotProductComplex10)(CppTypeFor<TypeCategory::Complex, 10> &,
     const Descriptor &, const Descriptor &, const char *source = nullptr,
     int line = 0);
 #endif
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(CppDotProductComplex16)(CppTypeFor<TypeCategory::Complex, 16> &,
     const Descriptor &, const Descriptor &, const char *source = nullptr,
     int line = 0);
diff --git a/flang/include/flang/Runtime/transformational.h b/flang/include/flang/Runtime/transformational.h
index faeaa1baa39ae2..d04fa685978837 100644
--- a/flang/include/flang/Runtime/transformational.h
+++ b/flang/include/flang/Runtime/transformational.h
@@ -53,7 +53,7 @@ void RTDECL(BesselJn_10)(Descriptor &result, int32_t n1, int32_t n2,
     int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselJn_16)(Descriptor &result, int32_t n1, int32_t n2,
     CppFloat128Type x, CppFloat128Type bn2, CppFloat128Type bn2_1,
     const char *sourceFile = nullptr, int line = 0);
@@ -76,7 +76,7 @@ void RTDECL(BesselJnX0_10)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselJnX0_16)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
@@ -101,7 +101,7 @@ void RTDECL(BesselYn_10)(Descriptor &result, int32_t n1, int32_t n2,
     int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselYn_16)(Descriptor &result, int32_t n1, int32_t n2,
     CppFloat128Type x, CppFloat128Type bn1, CppFloat128Type bn1_1,
     const char *sourceFile = nullptr, int line = 0);
@@ -124,7 +124,7 @@ void RTDECL(BesselYnX0_10)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 void RTDECL(BesselYnX0_16)(Descriptor &result, int32_t n1, int32_t n2,
     const char *sourceFile = nullptr, int line = 0);
 #endif
diff --git a/flang/include/flang/Tools/TargetSetup.h b/flang/include/flang/Tools/TargetSetup.h
index ee89249441c174..d6d36835bd2cb3 100644
--- a/flang/include/flang/Tools/TargetSetup.h
+++ b/flang/include/flang/Tools/TargetSetup.h
@@ -36,7 +36,7 @@ namespace Fortran::tools {
 #ifdef FLANG_RUNTIME_F128_MATH_LIB
   // we can use libquadmath wrappers
   constexpr bool f128Support = true;
-#elif LDBL_MANT_DIG == 113
+#elif HAS_LDBL128
   // we can use libm wrappers
   constexpr bool f128Support = true;
 #else
diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index ed28d8130808fa..ce9dd6b7b3df86 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -22,8 +22,9 @@
 #include <functional>
 #if HAS_QUADMATHLIB
 #include "quadmath.h"
-#include "flang/Common/float128.h"
 #endif
+#include "flang/Common/float128.h"
+#include "flang/Common/float80.h"
 #include <type_traits>
 
 namespace Fortran::evaluate {
@@ -414,7 +415,7 @@ template <> struct HostRuntimeLibrary<double, LibraryVersion::LibmExtensions> {
   static_assert(map.Verify(), "map must be sorted");
 };
 
-#if LDBL_MANT_DIG == 80 || LDBL_MANT_DIG == 113
+#if HAS_FLOAT80 || HAS_LDBL128
 template <>
 struct HostRuntimeLibrary<long double, LibraryVersion::LibmExtensions> {
   using F = FuncPointer<long double, long double>;
@@ -430,7 +431,7 @@ struct HostRuntimeLibrary<long double, LibraryVersion::LibmExtensions> {
   static constexpr HostRuntimeMap map{table};
   static_assert(map.Verify(), "map must be sorted");
 };
-#endif // LDBL_MANT_DIG == 80 || LDBL_MANT_DIG == 113
+#endif // HAS_FLOAT80 || HAS_LDBL128
 #endif //_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
 
 /// Define pgmath description
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index dc0dc47bda9a9d..4e6d92213c1241 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -750,7 +750,7 @@ prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
 
 // Generate a call to the Fortran runtime library providing
 // support for 128-bit float math.
-// On 'LDBL_MANT_DIG == 113' targets the implementation
+// On 'HAS_LDBL128' targets the implementation
 // is provided by FortranRuntime, otherwise, it is done via
 // FortranFloat128Math library. In the latter case the compiler
 // has to be built with FLANG_RUNTIME_F128_MATH_LIB to guarantee
diff --git a/flang/runtime/Float128Math/acos.cpp b/flang/runtime/Float128Math/acos.cpp
index 14ff6944856844..d9b4950aa1e35c 100644
--- a/flang/runtime/Float128Math/acos.cpp
+++ b/flang/runtime/Float128Math/acos.cpp
@@ -11,7 +11,7 @@
 namespace Fortran::runtime {
 extern "C" {
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDEF(AcosF128)(
     CppTypeFor<TypeCategory::Real, 16> x) {
   return Acos<true>::invoke(x);
diff --git a/flang/runtime/Float128Math/acosh.cpp b/flang/runtime/Float128Math/acosh.cpp
index 9d70804e44a470..c572673ef55e62 100644
--- a/flang/runtime/Float128Math/acosh.cpp
+++ b/flang/runtime/Float128Math/acosh.cpp
@@ -11,7 +11,7 @@
 namespace Fortran::runtime {
 extern "C" {
 
-#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
+#if HAS_LDBL128 || HAS_FLOAT128
 CppTypeFor<TypeCategory::Real, 16> RTDEF(AcoshF128)(
     CppTypeFor<TypeCategory::Real, 16> x) {
   return Acosh<true>::invoke(x);
diff --git a/flang/runtime/Float128Math/asin.cpp b/flang/runtime/Float128Math/asin.cpp
index 6781b23f0363db..57b6ffd9673605 100644
--- a/flang/runtime/Float128Math/asin.cpp
+++ b/flang/ru...
[truncated]

Copy link

github-actions bot commented Sep 19, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@vzakhari vzakhari merged commit fc51c7f into llvm:main Sep 19, 2024
8 checks passed
vzakhari added a commit that referenced this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:runtime flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants