diff --git a/flang/include/flang/Common/float80.h b/flang/include/flang/Common/float80.h new file mode 100644 index 000000000000..1838f7b13c8b --- /dev/null +++ b/flang/include/flang/Common/float80.h @@ -0,0 +1,43 @@ +/*===-- flang/Common/float80.h --------------------------------------*- C -*-=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===----------------------------------------------------------------------===*/ + +/* This header is usable in both C and C++ code. + * Isolates build compiler checks to determine if the 80-bit + * floating point format is supported via a particular C type. + * It defines CFloat80Type and CppFloat80Type aliases for this + * C type. + */ + +#ifndef FORTRAN_COMMON_FLOAT80_H_ +#define FORTRAN_COMMON_FLOAT80_H_ + +#include "api-attrs.h" +#include + +#if LDBL_MANT_DIG == 64 +#undef HAS_FLOAT80 +#define HAS_FLOAT80 1 +#endif + +#if defined(RT_DEVICE_COMPILATION) && defined(__CUDACC__) +/* + * 'long double' is treated as 'double' in the CUDA device code, + * and there is no support for 80-bit floating point format. + * This is probably true for most offload devices, so RT_DEVICE_COMPILATION + * check should be enough. For the time being, guard it with __CUDACC__ + * as well. + */ +#undef HAS_FLOAT80 +#endif + +#if HAS_FLOAT80 +typedef long double CFloat80Type; +typedef long double CppFloat80Type; +#endif + +#endif /* FORTRAN_COMMON_FLOAT80_H_ */ diff --git a/flang/include/flang/Runtime/complex.h b/flang/include/flang/Runtime/complex.h new file mode 100644 index 000000000000..be477d244155 --- /dev/null +++ b/flang/include/flang/Runtime/complex.h @@ -0,0 +1,33 @@ +//===-- include/flang/Runtime/complex.h -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// A single way to expose C++ complex class in files that can be used +// in F18 runtime build. With inclusion of this file std::complex +// and the related names become available, though, they may correspond +// to alternative definitions (e.g. from cuda::std namespace). + +#ifndef FORTRAN_RUNTIME_COMPLEX_H +#define FORTRAN_RUNTIME_COMPLEX_H + +#include "flang/Common/api-attrs.h" + +#if RT_USE_LIBCUDACXX && defined(RT_DEVICE_COMPILATION) +#include +namespace Fortran::runtime::rtcmplx { +using cuda::std::complex; +using cuda::std::conj; +} // namespace Fortran::runtime::rtcmplx +#else // !(RT_USE_LIBCUDACXX && defined(RT_DEVICE_COMPILATION)) +#include +namespace Fortran::runtime::rtcmplx { +using std::complex; +using std::conj; +} // namespace Fortran::runtime::rtcmplx +#endif // !(RT_USE_LIBCUDACXX && defined(RT_DEVICE_COMPILATION)) + +#endif // FORTRAN_RUNTIME_COMPLEX_H diff --git a/flang/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h index fe21dd544cf7..aef0fbd7ede5 100644 --- a/flang/include/flang/Runtime/cpp-type.h +++ b/flang/include/flang/Runtime/cpp-type.h @@ -13,8 +13,9 @@ #include "flang/Common/Fortran.h" #include "flang/Common/float128.h" +#include "flang/Common/float80.h" #include "flang/Common/uint128.h" -#include +#include "flang/Runtime/complex.h" #include #if __cplusplus >= 202302 #include @@ -70,9 +71,9 @@ template <> struct CppTypeForHelper { using type = double; #endif }; -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 template <> struct CppTypeForHelper { - using type = long double; + using type = CppFloat80Type; }; #endif #if __STDCPP_FLOAT128_T__ @@ -89,7 +90,7 @@ template <> struct CppTypeForHelper { #endif template struct CppTypeForHelper { - using type = std::complex>; + using type = rtcmplx::complex>; }; template <> struct CppTypeForHelper { diff --git a/flang/include/flang/Runtime/matmul-instances.inc b/flang/include/flang/Runtime/matmul-instances.inc index 32c6ab06d252..88e3067ca029 100644 --- a/flang/include/flang/Runtime/matmul-instances.inc +++ b/flang/include/flang/Runtime/matmul-instances.inc @@ -111,7 +111,7 @@ FOREACH_MATMUL_TYPE_PAIR(MATMUL_DIRECT_INSTANCE) FOREACH_MATMUL_TYPE_PAIR_WITH_INT16(MATMUL_INSTANCE) FOREACH_MATMUL_TYPE_PAIR_WITH_INT16(MATMUL_DIRECT_INSTANCE) -#if MATMUL_FORCE_ALL_TYPES || LDBL_MANT_DIG == 64 +#if MATMUL_FORCE_ALL_TYPES || HAS_FLOAT80 MATMUL_INSTANCE(Integer, 16, Real, 10) MATMUL_INSTANCE(Integer, 16, Complex, 10) MATMUL_INSTANCE(Real, 10, Integer, 16) @@ -133,7 +133,7 @@ MATMUL_DIRECT_INSTANCE(Complex, 16, Integer, 16) #endif #endif // MATMUL_FORCE_ALL_TYPES || (defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T) -#if MATMUL_FORCE_ALL_TYPES || LDBL_MANT_DIG == 64 +#if MATMUL_FORCE_ALL_TYPES || HAS_FLOAT80 #define FOREACH_MATMUL_TYPE_PAIR_WITH_REAL10(macro) \ macro(Integer, 1, Real, 10) \ macro(Integer, 1, Complex, 10) \ @@ -193,7 +193,7 @@ MATMUL_DIRECT_INSTANCE(Complex, 10, Complex, 16) MATMUL_DIRECT_INSTANCE(Complex, 16, Real, 10) MATMUL_DIRECT_INSTANCE(Complex, 16, Complex, 10) #endif -#endif // MATMUL_FORCE_ALL_TYPES || LDBL_MANT_DIG == 64 +#endif // MATMUL_FORCE_ALL_TYPES || HAS_FLOAT80 #if MATMUL_FORCE_ALL_TYPES || (LDBL_MANT_DIG == 113 || HAS_FLOAT128) #define FOREACH_MATMUL_TYPE_PAIR_WITH_REAL16(macro) \ diff --git a/flang/include/flang/Runtime/numeric.h b/flang/include/flang/Runtime/numeric.h index 84a5a7cd7a36..c3923ee2e0d8 100644 --- a/flang/include/flang/Runtime/numeric.h +++ b/flang/include/flang/Runtime/numeric.h @@ -44,7 +44,7 @@ CppTypeFor RTDECL(Ceiling8_8)( CppTypeFor RTDECL(Ceiling8_16)( CppTypeFor); #endif -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Ceiling10_1)( CppTypeFor); CppTypeFor RTDECL(Ceiling10_2)( @@ -78,7 +78,7 @@ CppTypeFor RTDECL(ErfcScaled4)( CppTypeFor); CppTypeFor RTDECL(ErfcScaled8)( CppTypeFor); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(ErfcScaled10)( CppTypeFor); #endif @@ -96,7 +96,7 @@ CppTypeFor RTDECL(Exponent8_4)( CppTypeFor); CppTypeFor RTDECL(Exponent8_8)( CppTypeFor); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Exponent10_4)( CppTypeFor); CppTypeFor RTDECL(Exponent10_8)( @@ -134,7 +134,7 @@ CppTypeFor RTDECL(Floor8_8)( CppTypeFor RTDECL(Floor8_16)( CppTypeFor); #endif -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Floor10_1)( CppTypeFor); CppTypeFor RTDECL(Floor10_2)( @@ -168,7 +168,7 @@ CppTypeFor RTDECL(Fraction4)( CppTypeFor); CppTypeFor RTDECL(Fraction8)( CppTypeFor); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Fraction10)( CppTypeFor); #endif @@ -180,7 +180,7 @@ CppTypeFor RTDECL(Fraction16)( // ISNAN / IEEE_IS_NAN bool RTDECL(IsNaN4)(CppTypeFor); bool RTDECL(IsNaN8)(CppTypeFor); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 bool RTDECL(IsNaN10)(CppTypeFor); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -212,7 +212,7 @@ CppTypeFor RTDECL(ModReal4)( CppTypeFor RTDECL(ModReal8)( CppTypeFor, CppTypeFor, const char *sourceFile = nullptr, int sourceLine = 0); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(ModReal10)( CppTypeFor, CppTypeFor, const char *sourceFile = nullptr, int sourceLine = 0); @@ -247,7 +247,7 @@ CppTypeFor RTDECL(ModuloReal4)( CppTypeFor RTDECL(ModuloReal8)( CppTypeFor, CppTypeFor, const char *sourceFile = nullptr, int sourceLine = 0); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(ModuloReal10)( CppTypeFor, CppTypeFor, const char *sourceFile = nullptr, int sourceLine = 0); @@ -283,7 +283,7 @@ CppTypeFor RTDECL(Nint8_8)( CppTypeFor RTDECL(Nint8_16)( CppTypeFor); #endif -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Nint10_1)( CppTypeFor); CppTypeFor RTDECL(Nint10_2)( @@ -319,7 +319,7 @@ CppTypeFor RTDECL(Nearest4)( CppTypeFor, bool positive); CppTypeFor RTDECL(Nearest8)( CppTypeFor, bool positive); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Nearest10)( CppTypeFor, bool positive); #endif @@ -333,7 +333,7 @@ CppTypeFor RTDECL(RRSpacing4)( CppTypeFor); CppTypeFor RTDECL(RRSpacing8)( CppTypeFor); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(RRSpacing10)( CppTypeFor); #endif @@ -347,7 +347,7 @@ CppTypeFor RTDECL(SetExponent4)( CppTypeFor, std::int64_t); CppTypeFor RTDECL(SetExponent8)( CppTypeFor, std::int64_t); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(SetExponent10)( CppTypeFor, std::int64_t); #endif @@ -361,7 +361,7 @@ CppTypeFor RTDECL(Scale4)( CppTypeFor, std::int64_t); CppTypeFor RTDECL(Scale8)( CppTypeFor, std::int64_t); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Scale10)( CppTypeFor, std::int64_t); #endif @@ -410,7 +410,7 @@ CppTypeFor RTDECL(Spacing4)( CppTypeFor); CppTypeFor RTDECL(Spacing8)( CppTypeFor); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(Spacing10)( CppTypeFor); #endif @@ -425,7 +425,7 @@ CppTypeFor RTDECL(FPow4i)( CppTypeFor RTDECL(FPow8i)( CppTypeFor b, CppTypeFor e); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(FPow10i)( CppTypeFor b, CppTypeFor e); @@ -442,7 +442,7 @@ CppTypeFor RTDECL(FPow4k)( CppTypeFor RTDECL(FPow8k)( CppTypeFor b, CppTypeFor e); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDECL(FPow10k)( CppTypeFor b, CppTypeFor e); diff --git a/flang/include/flang/Runtime/reduce.h b/flang/include/flang/Runtime/reduce.h index 60f54c393b4b..c016b37f9592 100644 --- a/flang/include/flang/Runtime/reduce.h +++ b/flang/include/flang/Runtime/reduce.h @@ -188,22 +188,26 @@ void RTDECL(ReduceReal8DimValue)(Descriptor &result, const Descriptor &array, ValueReductionOperation, const char *source, int line, int dim, const Descriptor *mask = nullptr, const double *identity = nullptr, bool ordered = true); -#if LDBL_MANT_DIG == 64 -long double RTDECL(ReduceReal10Ref)(const Descriptor &, - ReferenceReductionOperation, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr, - const long double *identity = nullptr, bool ordered = true); -long double RTDECL(ReduceReal10Value)(const Descriptor &, - ValueReductionOperation, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr, - const long double *identity = nullptr, bool ordered = true); +#if HAS_FLOAT80 +CppTypeFor RTDECL(ReduceReal10Ref)(const Descriptor &, + ReferenceReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); +CppTypeFor RTDECL(ReduceReal10Value)(const Descriptor &, + ValueReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(ReduceReal10DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation, const char *source, int line, - int dim, const Descriptor *mask = nullptr, - const long double *identity = nullptr, bool ordered = true); + ReferenceReductionOperation>, + const char *source, int line, int dim, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(ReduceReal10DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation, const char *source, int line, int dim, - const Descriptor *mask = nullptr, const long double *identity = nullptr, + ValueReductionOperation>, + const char *source, int line, int dim, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, bool ordered = true); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -225,112 +229,152 @@ void RTDECL(ReduceReal16DimValue)(Descriptor &result, const Descriptor &array, const CppFloat128Type *identity = nullptr, bool ordered = true); #endif -void RTDECL(CppReduceComplex2Ref)(std::complex &, const Descriptor &, - ReferenceReductionOperation>, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex2Value)(std::complex &, const Descriptor &, - ValueReductionOperation>, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); +void RTDECL(CppReduceComplex2Ref)(CppTypeFor &, + const Descriptor &, + ReferenceReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex2Value)(CppTypeFor &, + const Descriptor &, + ValueReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex2DimRef)(Descriptor &result, - const Descriptor &array, ReferenceReductionOperation>, + const Descriptor &array, + ReferenceReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex2DimValue)(Descriptor &result, - const Descriptor &array, ValueReductionOperation>, + const Descriptor &array, + ValueReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex3Ref)(std::complex &, const Descriptor &, - ReferenceReductionOperation>, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex3Value)(std::complex &, const Descriptor &, - ValueReductionOperation>, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex3Ref)(CppTypeFor &, + const Descriptor &, + ReferenceReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex3Value)(CppTypeFor &, + const Descriptor &, + ValueReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex3DimRef)(Descriptor &result, - const Descriptor &array, ReferenceReductionOperation>, + const Descriptor &array, + ReferenceReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex3DimValue)(Descriptor &result, - const Descriptor &array, ValueReductionOperation>, + const Descriptor &array, + ValueReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex4Ref)(std::complex &, const Descriptor &, - ReferenceReductionOperation>, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex4Value)(std::complex &, const Descriptor &, - ValueReductionOperation>, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex4Ref)(CppTypeFor &, + const Descriptor &, + ReferenceReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex4Value)(CppTypeFor &, + const Descriptor &, + ValueReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex4DimRef)(Descriptor &result, - const Descriptor &array, ReferenceReductionOperation>, + const Descriptor &array, + ReferenceReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex4DimValue)(Descriptor &result, - const Descriptor &array, ValueReductionOperation>, + const Descriptor &array, + ValueReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex8Ref)(std::complex &, const Descriptor &, - ReferenceReductionOperation>, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex8Value)(std::complex &, const Descriptor &, - ValueReductionOperation>, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex8Ref)(CppTypeFor &, + const Descriptor &, + ReferenceReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex8Value)(CppTypeFor &, + const Descriptor &, + ValueReductionOperation>, + const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex8DimRef)(Descriptor &result, - const Descriptor &array, ReferenceReductionOperation>, + const Descriptor &array, + ReferenceReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex8DimValue)(Descriptor &result, - const Descriptor &array, ValueReductionOperation>, + const Descriptor &array, + ValueReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -#if LDBL_MANT_DIG == 64 -void RTDECL(CppReduceComplex10Ref)(std::complex &, - const Descriptor &, ReferenceReductionOperation>, + const CppTypeFor *identity = nullptr, + bool ordered = true); +#if HAS_FLOAT80 +void RTDECL(CppReduceComplex10Ref)(CppTypeFor &, + const Descriptor &, + ReferenceReductionOperation>, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex10Value)(std::complex &, - const Descriptor &, ValueReductionOperation>, + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex10Value)(CppTypeFor &, + const Descriptor &, + ValueReductionOperation>, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); void RTDECL(CppReduceComplex10DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation>, const char *source, - int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex10DimValue)(Descriptor &result, - const Descriptor &array, ValueReductionOperation>, + ReferenceReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, bool ordered = true); + const CppTypeFor *identity = nullptr, + bool ordered = true); +void RTDECL(CppReduceComplex10DimValue)(Descriptor &result, + const Descriptor &array, + ValueReductionOperation>, + const char *source, int line, int dim, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, + bool ordered = true); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -void RTDECL(CppReduceComplex16Ref)(std::complex &, +void RTDECL(CppReduceComplex16Ref)(CppTypeFor &, const Descriptor &, - ReferenceReductionOperation>, + ReferenceReductionOperation>, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, + const CppTypeFor *identity = nullptr, bool ordered = true); -void RTDECL(CppReduceComplex16Value)(std::complex &, - const Descriptor &, ValueReductionOperation>, +void RTDECL(CppReduceComplex16Value)(CppTypeFor &, + const Descriptor &, + ValueReductionOperation>, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, + const CppTypeFor *identity = nullptr, bool ordered = true); void RTDECL(CppReduceComplex16DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation>, + ReferenceReductionOperation>, const char *source, int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, + const CppTypeFor *identity = nullptr, bool ordered = true); void RTDECL(CppReduceComplex16DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation>, const char *source, - int line, int dim, const Descriptor *mask = nullptr, - const std::complex *identity = nullptr, + ValueReductionOperation>, + const char *source, int line, int dim, const Descriptor *mask = nullptr, + const CppTypeFor *identity = nullptr, bool ordered = true); #endif diff --git a/flang/include/flang/Runtime/reduction.h b/flang/include/flang/Runtime/reduction.h index 97986c12e8a1..7eafacee69d0 100644 --- a/flang/include/flang/Runtime/reduction.h +++ b/flang/include/flang/Runtime/reduction.h @@ -68,34 +68,35 @@ float RTDECL(SumReal4)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); double RTDECL(SumReal8)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -#if LDBL_MANT_DIG == 64 -long double RTDECL(SumReal10)(const Descriptor &, const char *source, int line, - int dim = 0, const Descriptor *mask = nullptr); +#if HAS_FLOAT80 +CppTypeFor RTDECL(SumReal10)(const Descriptor &, + const char *source, int line, int dim = 0, + const Descriptor *mask = nullptr); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 CppFloat128Type RTDECL(SumReal16)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); #endif -void RTDECL(CppSumComplex2)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppSumComplex2)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -void RTDECL(CppSumComplex3)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppSumComplex3)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -void RTDECL(CppSumComplex4)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppSumComplex4)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -void RTDECL(CppSumComplex8)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppSumComplex8)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -#if LDBL_MANT_DIG == 64 -void RTDECL(CppSumComplex10)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +#if HAS_FLOAT80 +void RTDECL(CppSumComplex10)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -void RTDECL(CppSumComplex16)(std::complex &, +void RTDECL(CppSumComplex16)(CppTypeFor &, const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); #endif @@ -128,34 +129,35 @@ float RTDECL(ProductReal4)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); double RTDECL(ProductReal8)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -#if LDBL_MANT_DIG == 64 -long double RTDECL(ProductReal10)(const Descriptor &, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr); +#if HAS_FLOAT80 +CppTypeFor RTDECL(ProductReal10)(const Descriptor &, + const char *source, int line, int dim = 0, + const Descriptor *mask = nullptr); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 CppFloat128Type RTDECL(ProductReal16)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); #endif -void RTDECL(CppProductComplex2)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppProductComplex2)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -void RTDECL(CppProductComplex3)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppProductComplex3)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -void RTDECL(CppProductComplex4)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppProductComplex4)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -void RTDECL(CppProductComplex8)(std::complex &, const Descriptor &, - const char *source, int line, int dim = 0, +void RTDECL(CppProductComplex8)(CppTypeFor &, + const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -#if LDBL_MANT_DIG == 64 -void RTDECL(CppProductComplex10)(std::complex &, +#if HAS_FLOAT80 +void RTDECL(CppProductComplex10)(CppTypeFor &, const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -void RTDECL(CppProductComplex16)(std::complex &, +void RTDECL(CppProductComplex16)(CppTypeFor &, const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); #endif @@ -307,9 +309,10 @@ float RTDECL(MaxvalReal4)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); double RTDECL(MaxvalReal8)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -#if LDBL_MANT_DIG == 64 -long double RTDECL(MaxvalReal10)(const Descriptor &, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr); +#if HAS_FLOAT80 +CppTypeFor RTDECL(MaxvalReal10)(const Descriptor &, + const char *source, int line, int dim = 0, + const Descriptor *mask = nullptr); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 CppFloat128Type RTDECL(MaxvalReal16)(const Descriptor &, const char *source, @@ -338,9 +341,10 @@ float RTDECL(MinvalReal4)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); double RTDECL(MinvalReal8)(const Descriptor &, const char *source, int line, int dim = 0, const Descriptor *mask = nullptr); -#if LDBL_MANT_DIG == 64 -long double RTDECL(MinvalReal10)(const Descriptor &, const char *source, - int line, int dim = 0, const Descriptor *mask = nullptr); +#if HAS_FLOAT80 +CppTypeFor RTDECL(MinvalReal10)(const Descriptor &, + const char *source, int line, int dim = 0, + const Descriptor *mask = nullptr); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 CppFloat128Type RTDECL(MinvalReal16)(const Descriptor &, const char *source, @@ -363,12 +367,12 @@ float RTDECL(Norm2_4)( const Descriptor &, const char *source, int line, int dim = 0); double RTDECL(Norm2_8)( const Descriptor &, const char *source, int line, int dim = 0); -#if LDBL_MANT_DIG == 64 -long double RTDECL(Norm2_10)( +#if HAS_FLOAT80 +CppTypeFor RTDECL(Norm2_10)( const Descriptor &, const char *source, int line, int dim = 0); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -long double RTDECL(Norm2_16)( +CppFloat128Type RTDECL(Norm2_16)( const Descriptor &, const char *source, int line, int dim = 0); void RTDECL(Norm2DimReal16)( Descriptor &, const Descriptor &, int dim, const char *source, int line); @@ -413,29 +417,33 @@ float RTDECL(DotProductReal4)(const Descriptor &, const Descriptor &, const char *source = nullptr, int line = 0); double RTDECL(DotProductReal8)(const Descriptor &, const Descriptor &, const char *source = nullptr, int line = 0); -#if LDBL_MANT_DIG == 64 -long double RTDECL(DotProductReal10)(const Descriptor &, const Descriptor &, - const char *source = nullptr, int line = 0); +#if HAS_FLOAT80 +CppTypeFor RTDECL(DotProductReal10)(const Descriptor &, + const Descriptor &, const char *source = nullptr, int line = 0); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 CppFloat128Type RTDECL(DotProductReal16)(const Descriptor &, const Descriptor &, const char *source = nullptr, int line = 0); #endif -void RTDECL(CppDotProductComplex2)(std::complex &, const Descriptor &, - const Descriptor &, const char *source = nullptr, int line = 0); -void RTDECL(CppDotProductComplex3)(std::complex &, const Descriptor &, - const Descriptor &, const char *source = nullptr, int line = 0); -void RTDECL(CppDotProductComplex4)(std::complex &, const Descriptor &, - const Descriptor &, const char *source = nullptr, int line = 0); -void RTDECL(CppDotProductComplex8)(std::complex &, const Descriptor &, - const Descriptor &, const char *source = nullptr, int line = 0); -#if LDBL_MANT_DIG == 64 -void RTDECL(CppDotProductComplex10)(std::complex &, +void RTDECL(CppDotProductComplex2)(CppTypeFor &, + const Descriptor &, const Descriptor &, const char *source = nullptr, + int line = 0); +void RTDECL(CppDotProductComplex3)(CppTypeFor &, + const Descriptor &, const Descriptor &, const char *source = nullptr, + int line = 0); +void RTDECL(CppDotProductComplex4)(CppTypeFor &, + const Descriptor &, const Descriptor &, const char *source = nullptr, + int line = 0); +void RTDECL(CppDotProductComplex8)(CppTypeFor &, + const Descriptor &, const Descriptor &, const char *source = nullptr, + int line = 0); +#if HAS_FLOAT80 +void RTDECL(CppDotProductComplex10)(CppTypeFor &, const Descriptor &, const Descriptor &, const char *source = nullptr, int line = 0); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -void RTDECL(CppDotProductComplex16)(std::complex &, +void RTDECL(CppDotProductComplex16)(CppTypeFor &, const Descriptor &, const Descriptor &, const char *source = nullptr, int line = 0); #endif diff --git a/flang/include/flang/Runtime/transformational.h b/flang/include/flang/Runtime/transformational.h index a39b872f376a..faeaa1baa39a 100644 --- a/flang/include/flang/Runtime/transformational.h +++ b/flang/include/flang/Runtime/transformational.h @@ -45,10 +45,12 @@ void RTDECL(BesselJn_4)(Descriptor &result, int32_t n1, int32_t n2, float x, void RTDECL(BesselJn_8)(Descriptor &result, int32_t n1, int32_t n2, double x, double bn2, double bn2_1, const char *sourceFile = nullptr, int line = 0); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDECL(BesselJn_10)(Descriptor &result, int32_t n1, int32_t n2, - long double x, long double bn2, long double bn2_1, - const char *sourceFile = nullptr, int line = 0); + CppTypeFor x, + CppTypeFor bn2, + CppTypeFor bn2_1, const char *sourceFile = nullptr, + int line = 0); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -69,7 +71,7 @@ void RTDECL(BesselJnX0_4)(Descriptor &result, int32_t n1, int32_t n2, void RTDECL(BesselJnX0_8)(Descriptor &result, int32_t n1, int32_t n2, const char *sourceFile = nullptr, int line = 0); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDECL(BesselJnX0_10)(Descriptor &result, int32_t n1, int32_t n2, const char *sourceFile = nullptr, int line = 0); #endif @@ -91,10 +93,12 @@ void RTDECL(BesselYn_4)(Descriptor &result, int32_t n1, int32_t n2, float x, void RTDECL(BesselYn_8)(Descriptor &result, int32_t n1, int32_t n2, double x, double bn1, double bn1_1, const char *sourceFile = nullptr, int line = 0); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDECL(BesselYn_10)(Descriptor &result, int32_t n1, int32_t n2, - long double x, long double bn1, long double bn1_1, - const char *sourceFile = nullptr, int line = 0); + CppTypeFor x, + CppTypeFor bn1, + CppTypeFor bn1_1, const char *sourceFile = nullptr, + int line = 0); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -115,7 +119,7 @@ void RTDECL(BesselYnX0_4)(Descriptor &result, int32_t n1, int32_t n2, void RTDECL(BesselYnX0_8)(Descriptor &result, int32_t n1, int32_t n2, const char *sourceFile = nullptr, int line = 0); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDECL(BesselYnX0_10)(Descriptor &result, int32_t n1, int32_t n2, const char *sourceFile = nullptr, int line = 0); #endif diff --git a/flang/runtime/complex-powi.cpp b/flang/runtime/complex-powi.cpp index 77031e402427..d7a63724b96c 100644 --- a/flang/runtime/complex-powi.cpp +++ b/flang/runtime/complex-powi.cpp @@ -7,11 +7,13 @@ * ===-----------------------------------------------------------------------=== */ #include "flang/Common/float128.h" +#include "flang/Runtime/cpp-type.h" #include "flang/Runtime/entry-names.h" #include #include #include +namespace Fortran::runtime { #ifdef __clang_major__ #pragma clang diagnostic ignored "-Wc99-extensions" #endif @@ -114,35 +116,35 @@ extern "C" Qcomplex RTNAME(cqpowk)(Qcomplex base, std::int64_t exp) { // MSVC doesn't allow including or in C++17 mode to get // the Windows definitions of these structs so just redefine here. struct Fcomplex { - float re; - float im; + CppTypeFor re; + CppTypeFor im; }; struct Dcomplex { - double re; - double im; + CppTypeFor re; + CppTypeFor im; }; extern "C" Fcomplex RTNAME(cpowi)(Fcomplex base, std::int32_t exp) { - auto cppbase = *(std::complex *)(&base); + auto cppbase = *(CppTypeFor *)(&base); auto cppres = tgpowi(cppbase, exp); return *(Fcomplex *)(&cppres); } extern "C" Dcomplex RTNAME(zpowi)(Dcomplex base, std::int32_t exp) { - auto cppbase = *(std::complex *)(&base); + auto cppbase = *(CppTypeFor *)(&base); auto cppres = tgpowi(cppbase, exp); return *(Dcomplex *)(&cppres); } extern "C" Fcomplex RTNAME(cpowk)(Fcomplex base, std::int64_t exp) { - auto cppbase = *(std::complex *)(&base); + auto cppbase = *(CppTypeFor *)(&base); auto cppres = tgpowi(cppbase, exp); return *(Fcomplex *)(&cppres); } extern "C" Dcomplex RTNAME(zpowk)(Dcomplex base, std::int64_t exp) { - auto cppbase = *(std::complex *)(&base); + auto cppbase = *(CppTypeFor *)(&base); auto cppres = tgpowi(cppbase, exp); return *(Dcomplex *)(&cppres); } @@ -154,15 +156,16 @@ struct Qcomplex { }; extern "C" Dcomplex RTNAME(cqpowi)(Qcomplex base, std::int32_t exp) { - auto cppbase = *(std::complex *)(&base); + auto cppbase = *(rtcmplx::complex *)(&base); auto cppres = tgpowi(cppbase, exp); return *(Qcomplex *)(&cppres); } extern "C" Dcomplex RTNAME(cqpowk)(Qcomplex base, std::int64_t exp) { - auto cppbase = *(std::complex *)(&base); + auto cppbase = *(rtcmplx::complex *)(&base); auto cppres = tgpowi(cppbase, exp); return *(Qcomplex *)(&cppres); } #endif #endif +} // namespace Fortran::runtime diff --git a/flang/runtime/complex-reduction.c b/flang/runtime/complex-reduction.c index 37ce3fa41001..232c5452488f 100644 --- a/flang/runtime/complex-reduction.c +++ b/flang/runtime/complex-reduction.c @@ -119,7 +119,7 @@ ADAPT_REDUCTION(SumComplex4, float_Complex_t, CppComplexFloat, CMPLXF, REDUCTION_ARGS, REDUCTION_ARG_NAMES) ADAPT_REDUCTION(SumComplex8, double_Complex_t, CppComplexDouble, CMPLX, REDUCTION_ARGS, REDUCTION_ARG_NAMES) -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 ADAPT_REDUCTION(SumComplex10, long_double_Complex_t, CppComplexLongDouble, CMPLXL, REDUCTION_ARGS, REDUCTION_ARG_NAMES) #endif @@ -133,7 +133,7 @@ ADAPT_REDUCTION(ProductComplex4, float_Complex_t, CppComplexFloat, CMPLXF, REDUCTION_ARGS, REDUCTION_ARG_NAMES) ADAPT_REDUCTION(ProductComplex8, double_Complex_t, CppComplexDouble, CMPLX, REDUCTION_ARGS, REDUCTION_ARG_NAMES) -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 ADAPT_REDUCTION(ProductComplex10, long_double_Complex_t, CppComplexLongDouble, CMPLXL, REDUCTION_ARGS, REDUCTION_ARG_NAMES) #endif @@ -147,7 +147,7 @@ ADAPT_REDUCTION(DotProductComplex4, float_Complex_t, CppComplexFloat, CMPLXF, DOT_PRODUCT_ARGS, DOT_PRODUCT_ARG_NAMES) ADAPT_REDUCTION(DotProductComplex8, double_Complex_t, CppComplexDouble, CMPLX, DOT_PRODUCT_ARGS, DOT_PRODUCT_ARG_NAMES) -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 ADAPT_REDUCTION(DotProductComplex10, long_double_Complex_t, CppComplexLongDouble, CMPLXL, DOT_PRODUCT_ARGS, DOT_PRODUCT_ARG_NAMES) #endif @@ -173,7 +173,7 @@ ADAPT_REDUCTION(ReduceComplex8Ref, double_Complex_t, CppComplexDouble, CMPLX, ADAPT_REDUCTION(ReduceComplex8Value, double_Complex_t, CppComplexDouble, CMPLX, RARGS, REDUCE_ARG_NAMES) #undef RARGS -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 #define RARGS REDUCE_ARGS(long_double_Complex_t, long_double_Complex_t_ref_op) ADAPT_REDUCTION(ReduceComplex10Ref, long_double_Complex_t, CppComplexLongDouble, CMPLXL, RARGS, REDUCE_ARG_NAMES) diff --git a/flang/runtime/dot-product.cpp b/flang/runtime/dot-product.cpp index 977698269bcb..aafef379fad4 100644 --- a/flang/runtime/dot-product.cpp +++ b/flang/runtime/dot-product.cpp @@ -21,11 +21,6 @@ namespace Fortran::runtime { // Beware: DOT_PRODUCT of COMPLEX data uses the complex conjugate of the first // argument; MATMUL does not. -// Suppress the warnings about calling __host__-only std::complex operators, -// defined in C++ STD header files, from __device__ code. -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // General accumulator for any type and stride; this is not used for // contiguous numeric vectors. template @@ -42,7 +37,7 @@ public: const XT &xElement{*x_.Element(&xAt)}; const YT &yElement{*y_.Element(&yAt)}; if constexpr (RCAT == TypeCategory::Complex) { - sum_ += std::conj(static_cast(xElement)) * + sum_ += rtcmplx::conj(static_cast(xElement)) * static_cast(yElement); } else { sum_ += static_cast(xElement) * static_cast(yElement); @@ -77,9 +72,9 @@ static inline RT_API_ATTRS CppTypeFor DoDotProduct( // TODO: call BLAS-1 SDOT or SDSDOT } else if constexpr (std::is_same_v) { // TODO: call BLAS-1 DDOT - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-1 CDOTC - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-1 ZDOTC } } @@ -89,12 +84,12 @@ static inline RT_API_ATTRS CppTypeFor DoDotProduct( AccumType accum{}; if constexpr (RCAT == TypeCategory::Complex) { for (SubscriptValue j{0}; j < n; ++j) { - // std::conj() may instantiate its argument twice, + // conj() may instantiate its argument twice, // so xp has to be incremented separately. // This is a workaround for an alleged bug in clang, // that shows up as: // warning: multiple unsequenced modifications to 'xp' - accum += std::conj(static_cast(*xp)) * + accum += rtcmplx::conj(static_cast(*xp)) * static_cast(*yp++); xp++; } @@ -117,8 +112,6 @@ static inline RT_API_ATTRS CppTypeFor DoDotProduct( return static_cast(accumulator.GetResult()); } -RT_DIAG_POP - template struct DotProduct { using Result = CppTypeFor; template struct DP1 { @@ -197,7 +190,7 @@ CppTypeFor RTDEF(DotProductReal8)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(DotProductReal10)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); @@ -218,7 +211,7 @@ void RTDEF(CppDotProductComplex8)(CppTypeFor &result, const Descriptor &x, const Descriptor &y, const char *source, int line) { result = DotProduct{}(x, y, source, line); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(CppDotProductComplex10)( CppTypeFor &result, const Descriptor &x, const Descriptor &y, const char *source, int line) { diff --git a/flang/runtime/extrema.cpp b/flang/runtime/extrema.cpp index d6e9633372f5..2658709b7de8 100644 --- a/flang/runtime/extrema.cpp +++ b/flang/runtime/extrema.cpp @@ -236,7 +236,7 @@ void RTDEF(MaxlocReal8)(Descriptor &result, const Descriptor &x, int kind, TotalNumericMaxOrMinLoc( "MAXLOC", result, x, kind, source, line, mask, back); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(MaxlocReal10)(Descriptor &result, const Descriptor &x, int kind, const char *source, int line, const Descriptor *mask, bool back) { TotalNumericMaxOrMinLoc( @@ -292,7 +292,7 @@ void RTDEF(MinlocReal8)(Descriptor &result, const Descriptor &x, int kind, TotalNumericMaxOrMinLoc( "MINLOC", result, x, kind, source, line, mask, back); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(MinlocReal10)(Descriptor &result, const Descriptor &x, int kind, const char *source, int line, const Descriptor *mask, bool back) { TotalNumericMaxOrMinLoc( @@ -614,7 +614,7 @@ CppTypeFor RTDEF(MaxvalReal8)(const Descriptor &x, return TotalNumericMaxOrMin( x, source, line, dim, mask, "MAXVAL"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(MaxvalReal10)(const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { return TotalNumericMaxOrMin( @@ -674,7 +674,7 @@ CppTypeFor RTDEF(MinvalReal8)(const Descriptor &x, return TotalNumericMaxOrMin( x, source, line, dim, mask, "MINVAL"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(MinvalReal10)(const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { return TotalNumericMaxOrMin( @@ -730,7 +730,7 @@ CppTypeFor RTDEF(Norm2_8)( return GetTotalReduction( x, source, line, dim, nullptr, Norm2Accumulator<8>{x}, "NORM2"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Norm2_10)( const Descriptor &x, const char *source, int line, int dim) { return GetTotalReduction( diff --git a/flang/runtime/matmul-transpose.cpp b/flang/runtime/matmul-transpose.cpp index 283472650a1c..bafa05056beb 100644 --- a/flang/runtime/matmul-transpose.cpp +++ b/flang/runtime/matmul-transpose.cpp @@ -32,11 +32,6 @@ namespace { using namespace Fortran::runtime; -// Suppress the warnings about calling __host__-only std::complex operators, -// defined in C++ STD header files, from __device__ code. -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // Contiguous numeric TRANSPOSE(matrix)*matrix multiplication // TRANSPOSE(matrix(n, rows)) * matrix(n,cols) -> // matrix(rows, n) * matrix(n,cols) -> matrix(rows,cols) @@ -91,8 +86,6 @@ inline static RT_API_ATTRS void MatrixTransposedTimesMatrix( } } -RT_DIAG_POP - template inline static RT_API_ATTRS void MatrixTransposedTimesMatrixHelper( CppTypeFor *RESTRICT product, SubscriptValue rows, @@ -118,9 +111,6 @@ inline static RT_API_ATTRS void MatrixTransposedTimesMatrixHelper( } } -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // Contiguous numeric matrix*vector multiplication // matrix(rows,n) * column vector(n) -> column vector(rows) // Straightforward algorithm: @@ -158,8 +148,6 @@ inline static RT_API_ATTRS void MatrixTransposedTimesVector( } } -RT_DIAG_POP - template inline static RT_API_ATTRS void MatrixTransposedTimesVectorHelper( CppTypeFor *RESTRICT product, SubscriptValue rows, @@ -174,9 +162,6 @@ inline static RT_API_ATTRS void MatrixTransposedTimesVectorHelper( } } -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // Implements an instance of MATMUL for given argument types. template @@ -341,8 +326,6 @@ inline static RT_API_ATTRS void DoMatmulTranspose( } } -RT_DIAG_POP - template struct MatmulTransposeHelper { diff --git a/flang/runtime/matmul.cpp b/flang/runtime/matmul.cpp index 252557e2f9e7..a5737a9bc620 100644 --- a/flang/runtime/matmul.cpp +++ b/flang/runtime/matmul.cpp @@ -31,11 +31,6 @@ namespace { using namespace Fortran::runtime; -// Suppress the warnings about calling __host__-only std::complex operators, -// defined in C++ STD header files, from __device__ code. -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // General accumulator for any type and stride; this is not used for // contiguous numeric cases. template @@ -112,8 +107,6 @@ inline RT_API_ATTRS void MatrixTimesMatrix( } } -RT_DIAG_POP - template inline RT_API_ATTRS void MatrixTimesMatrixHelper( CppTypeFor *RESTRICT product, SubscriptValue rows, @@ -139,9 +132,6 @@ inline RT_API_ATTRS void MatrixTimesMatrixHelper( } } -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // Contiguous numeric matrix*vector multiplication // matrix(rows,n) * column vector(n) -> column vector(rows) // Straightforward algorithm: @@ -179,8 +169,6 @@ inline RT_API_ATTRS void MatrixTimesVector( } } -RT_DIAG_POP - template inline RT_API_ATTRS void MatrixTimesVectorHelper( CppTypeFor *RESTRICT product, SubscriptValue rows, @@ -194,9 +182,6 @@ inline RT_API_ATTRS void MatrixTimesVectorHelper( } } -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // Contiguous numeric vector*matrix multiplication // row vector(n) * matrix(n,cols) -> row vector(cols) // Straightforward algorithm: @@ -235,8 +220,6 @@ inline RT_API_ATTRS void VectorTimesMatrix( } } -RT_DIAG_POP - template inline RT_API_ATTRS void VectorTimesMatrixHelper( @@ -251,9 +234,6 @@ inline RT_API_ATTRS void VectorTimesMatrixHelper( } } -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - // Implements an instance of MATMUL for given argument types. template @@ -344,9 +324,9 @@ static inline RT_API_ATTRS void DoMatmul( // TODO: try using CUTLASS for device. } else if constexpr (std::is_same_v) { // TODO: call BLAS-3 DGEMM - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-3 CGEMM - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-3 ZGEMM } } @@ -361,9 +341,9 @@ static inline RT_API_ATTRS void DoMatmul( // TODO: call BLAS-2 SGEMV(x,y) } else if constexpr (std::is_same_v) { // TODO: call BLAS-2 DGEMV(x,y) - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-2 CGEMV(x,y) - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-2 ZGEMV(x,y) } } @@ -377,9 +357,9 @@ static inline RT_API_ATTRS void DoMatmul( // TODO: call BLAS-2 SGEMV(y,x) } else if constexpr (std::is_same_v) { // TODO: call BLAS-2 DGEMV(y,x) - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-2 CGEMV(y,x) - } else if constexpr (std::is_same_v>) { + } else if constexpr (std::is_same_v>) { // TODO: call BLAS-2 ZGEMV(y,x) } } @@ -441,8 +421,6 @@ static inline RT_API_ATTRS void DoMatmul( } } -RT_DIAG_POP - template struct MatmulHelper { diff --git a/flang/runtime/numeric.cpp b/flang/runtime/numeric.cpp index 9a8ddc661556..23f8da3f81f1 100644 --- a/flang/runtime/numeric.cpp +++ b/flang/runtime/numeric.cpp @@ -144,7 +144,7 @@ inline RT_API_ATTRS CppTypeFor SelectedRealKind( #ifdef FLANG_RUNTIME_NO_REAL_3 mask &= ~(1 << 3); #endif -#if LDBL_MANT_DIG < 64 || defined FLANG_RUNTIME_NO_REAL_10 +#if !HAS_FLOAT80 || defined FLANG_RUNTIME_NO_REAL_10 mask &= ~(1 << 10); #endif #if LDBL_MANT_DIG < 64 || defined FLANG_RUNTIME_NO_REAL_16 @@ -276,7 +276,7 @@ CppTypeFor RTDEF(Ceiling8_16)( return Ceiling>(x); } #endif -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Ceiling10_1)( CppTypeFor x) { return Ceiling>(x); @@ -332,7 +332,7 @@ CppTypeFor RTDEF(ErfcScaled8)( CppTypeFor x) { return ErfcScaled(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(ErfcScaled10)( CppTypeFor x) { return ErfcScaled(x); @@ -361,7 +361,7 @@ CppTypeFor RTDEF(Exponent8_8)( CppTypeFor x) { return Exponent>(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Exponent10_4)( CppTypeFor x) { return Exponent>(x); @@ -416,7 +416,7 @@ CppTypeFor RTDEF(Floor8_16)( return Floor>(x); } #endif -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Floor10_1)( CppTypeFor x) { return Floor>(x); @@ -472,7 +472,7 @@ CppTypeFor RTDEF(Fraction8)( CppTypeFor x) { return Fraction(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Fraction10)( CppTypeFor x) { return Fraction(x); @@ -485,7 +485,7 @@ bool RTDEF(IsFinite4)(CppTypeFor x) { bool RTDEF(IsFinite8)(CppTypeFor x) { return std::isfinite(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 bool RTDEF(IsFinite10)(CppTypeFor x) { return std::isfinite(x); } @@ -501,7 +501,7 @@ bool RTDEF(IsNaN4)(CppTypeFor x) { bool RTDEF(IsNaN8)(CppTypeFor x) { return std::isnan(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 bool RTDEF(IsNaN10)(CppTypeFor x) { return std::isnan(x); } @@ -553,7 +553,7 @@ CppTypeFor RTDEF(ModReal8)( const char *sourceFile, int sourceLine) { return RealMod(x, p, sourceFile, sourceLine); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(ModReal10)( CppTypeFor x, CppTypeFor p, const char *sourceFile, int sourceLine) { @@ -603,7 +603,7 @@ CppTypeFor RTDEF(ModuloReal8)( const char *sourceFile, int sourceLine) { return RealMod(x, p, sourceFile, sourceLine); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(ModuloReal10)( CppTypeFor x, CppTypeFor p, const char *sourceFile, int sourceLine) { @@ -619,7 +619,7 @@ CppTypeFor RTDEF(Nearest8)( CppTypeFor x, bool positive) { return Nearest<53>(x, positive); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Nearest10)( CppTypeFor x, bool positive) { return Nearest<64>(x, positive); @@ -670,7 +670,7 @@ CppTypeFor RTDEF(Nint8_16)( return Nint>(x); } #endif -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Nint10_1)( CppTypeFor x) { return Nint>(x); @@ -726,7 +726,7 @@ CppTypeFor RTDEF(RRSpacing8)( CppTypeFor x) { return RRSpacing<53>(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(RRSpacing10)( CppTypeFor x) { return RRSpacing<64>(x); @@ -741,7 +741,7 @@ CppTypeFor RTDEF(SetExponent8)( CppTypeFor x, std::int64_t p) { return SetExponent(x, p); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(SetExponent10)( CppTypeFor x, std::int64_t p) { return SetExponent(x, p); @@ -756,7 +756,7 @@ CppTypeFor RTDEF(Scale8)( CppTypeFor x, std::int64_t p) { return Scale(x, p); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Scale10)( CppTypeFor x, std::int64_t p) { return Scale(x, p); @@ -876,7 +876,7 @@ CppTypeFor RTDEF(Spacing8)( CppTypeFor x) { return Spacing<53>(x); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(Spacing10)( CppTypeFor x) { return Spacing<64>(x); @@ -893,7 +893,7 @@ CppTypeFor RTDEF(FPow8i)( CppTypeFor e) { return FPowI(b, e); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(FPow10i)( CppTypeFor b, CppTypeFor e) { @@ -918,7 +918,7 @@ CppTypeFor RTDEF(FPow8k)( CppTypeFor e) { return FPowI(b, e); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(FPow10k)( CppTypeFor b, CppTypeFor e) { diff --git a/flang/runtime/product.cpp b/flang/runtime/product.cpp index 7fc0fcd3b107..39b40d82b054 100644 --- a/flang/runtime/product.cpp +++ b/flang/runtime/product.cpp @@ -36,16 +36,11 @@ private: INTERMEDIATE product_{1}; }; -// Suppress the warnings about calling __host__-only std::complex operators, -// defined in C++ STD header files, from __device__ code. -RT_DIAG_PUSH -RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN - template class ComplexProductAccumulator { public: explicit RT_API_ATTRS ComplexProductAccumulator(const Descriptor &array) : array_{array} {} - RT_API_ATTRS void Reinitialize() { product_ = std::complex{1, 0}; } + RT_API_ATTRS void Reinitialize() { product_ = rtcmplx::complex{1, 0}; } template RT_API_ATTRS void GetResult(A *p, int /*zeroBasedDim*/ = -1) const { using ResultPart = typename A::value_type; @@ -60,11 +55,9 @@ public: private: const Descriptor &array_; - std::complex product_{1, 0}; + rtcmplx::complex product_{1, 0}; }; -RT_DIAG_POP - extern "C" { RT_EXT_API_GROUP_BEGIN @@ -116,7 +109,7 @@ CppTypeFor RTDEF(ProductReal8)(const Descriptor &x, NonComplexProductAccumulator>{x}, "PRODUCT"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(ProductReal10)(const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { return GetTotalReduction(x, source, line, dim, mask, @@ -147,7 +140,7 @@ void RTDEF(CppProductComplex8)(CppTypeFor &result, mask, ComplexProductAccumulator>{x}, "PRODUCT"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(CppProductComplex10)(CppTypeFor &result, const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp index 69de9b8c96fb..9ec961fd0587 100644 --- a/flang/runtime/random.cpp +++ b/flang/runtime/random.cpp @@ -66,7 +66,7 @@ void RTNAME(RandomNumber)( return; case 10: if constexpr (HasCppTypeFor) { -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 Generate, 64>(harvest); return; #endif diff --git a/flang/runtime/reduce.cpp b/flang/runtime/reduce.cpp index 2f4bb6ea159c..6b62e1cf1e76 100644 --- a/flang/runtime/reduce.cpp +++ b/flang/runtime/reduce.cpp @@ -395,45 +395,49 @@ void RTDEF(ReduceReal8DimValue)(Descriptor &result, const Descriptor &array, PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } -#if LDBL_MANT_DIG == 64 -long double RTDEF(ReduceReal10Ref)(const Descriptor &array, - ReferenceReductionOperation operation, const char *source, - int line, int dim, const Descriptor *mask, const long double *identity, - bool ordered) { +#if HAS_FLOAT80 +CppTypeFor RTDEF(ReduceReal10Ref)( + const Descriptor &array, + ReferenceReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; return GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator{ + ReduceAccumulator, false>{ array, operation, identity, terminator}, "REDUCE"); } -long double RTDEF(ReduceReal10Value)(const Descriptor &array, - ValueReductionOperation operation, const char *source, - int line, int dim, const Descriptor *mask, const long double *identity, - bool ordered) { +CppTypeFor RTDEF(ReduceReal10Value)( + const Descriptor &array, + ValueReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; return GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator{ + ReduceAccumulator, true>{ array, operation, identity, terminator}, "REDUCE"); } void RTDEF(ReduceReal10DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation operation, const char *source, - int line, int dim, const Descriptor *mask, const long double *identity, - bool ordered) { + ReferenceReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator; + using Accumulator = + ReduceAccumulator, false>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } void RTDEF(ReduceReal10DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation operation, const char *source, - int line, int dim, const Descriptor *mask, const long double *identity, - bool ordered) { + ValueReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator; + using Accumulator = + ReduceAccumulator, true>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); @@ -484,187 +488,199 @@ void RTDEF(ReduceReal16DimValue)(Descriptor &result, const Descriptor &array, } #endif -void RTDEF(CppReduceComplex4Ref)(std::complex &result, +void RTDEF(CppReduceComplex4Ref)(CppTypeFor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, false>{ + ReduceAccumulator, false>{ array, operation, identity, terminator}, "REDUCE"); } -void RTDEF(CppReduceComplex4Value)(std::complex &result, +void RTDEF(CppReduceComplex4Value)(CppTypeFor &result, const Descriptor &array, - ValueReductionOperation> operation, const char *source, - int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + ValueReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, true>{ + ReduceAccumulator, true>{ array, operation, identity, terminator}, "REDUCE"); } void RTDEF(CppReduceComplex4DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, false>; + using Accumulator = + ReduceAccumulator, false>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } void RTDEF(CppReduceComplex4DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation> operation, const char *source, - int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + ValueReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, true>; + using Accumulator = + ReduceAccumulator, true>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } -void RTDEF(CppReduceComplex8Ref)(std::complex &result, +void RTDEF(CppReduceComplex8Ref)(CppTypeFor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, false>{ + ReduceAccumulator, false>{ array, operation, identity, terminator}, "REDUCE"); } -void RTDEF(CppReduceComplex8Value)(std::complex &result, +void RTDEF(CppReduceComplex8Value)(CppTypeFor &result, const Descriptor &array, - ValueReductionOperation> operation, const char *source, - int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + ValueReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, true>{ + ReduceAccumulator, true>{ array, operation, identity, terminator}, "REDUCE"); } void RTDEF(CppReduceComplex8DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, false>; + using Accumulator = + ReduceAccumulator, false>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } void RTDEF(CppReduceComplex8DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation> operation, const char *source, - int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + ValueReductionOperation> operation, + const char *source, int line, int dim, const Descriptor *mask, + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, true>; + using Accumulator = + ReduceAccumulator, true>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } -#if LDBL_MANT_DIG == 64 -void RTDEF(CppReduceComplex10Ref)(std::complex &result, +#if HAS_FLOAT80 +void RTDEF(CppReduceComplex10Ref)(CppTypeFor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> + operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, false>{ + ReduceAccumulator, false>{ array, operation, identity, terminator}, "REDUCE"); } -void RTDEF(CppReduceComplex10Value)(std::complex &result, - const Descriptor &array, - ValueReductionOperation> operation, +void RTDEF(CppReduceComplex10Value)( + CppTypeFor &result, const Descriptor &array, + ValueReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, true>{ + ReduceAccumulator, true>{ array, operation, identity, terminator}, "REDUCE"); } void RTDEF(CppReduceComplex10DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> + operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, false>; + using Accumulator = + ReduceAccumulator, false>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } void RTDEF(CppReduceComplex10DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation> operation, + ValueReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, true>; + using Accumulator = + ReduceAccumulator, true>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -void RTDEF(CppReduceComplex16Ref)(std::complex &result, +void RTDEF(CppReduceComplex16Ref)(CppTypeFor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> + operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, false>{ + ReduceAccumulator, false>{ array, operation, identity, terminator}, "REDUCE"); } -void RTDEF(CppReduceComplex16Value)(std::complex &result, - const Descriptor &array, - ValueReductionOperation> operation, +void RTDEF(CppReduceComplex16Value)( + CppTypeFor &result, const Descriptor &array, + ValueReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; result = GetTotalReduction(array, source, line, dim, mask, - ReduceAccumulator, true>{ + ReduceAccumulator, true>{ array, operation, identity, terminator}, "REDUCE"); } void RTDEF(CppReduceComplex16DimRef)(Descriptor &result, const Descriptor &array, - ReferenceReductionOperation> operation, + ReferenceReductionOperation> + operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, false>; + using Accumulator = + ReduceAccumulator, false>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); } void RTDEF(CppReduceComplex16DimValue)(Descriptor &result, const Descriptor &array, - ValueReductionOperation> operation, + ValueReductionOperation> operation, const char *source, int line, int dim, const Descriptor *mask, - const std::complex *identity, bool ordered) { + const CppTypeFor *identity, bool ordered) { Terminator terminator{source, line}; - using Accumulator = ReduceAccumulator, true>; + using Accumulator = + ReduceAccumulator, true>; Accumulator accumulator{array, operation, identity, terminator}; PartialReduction(result, array, array.ElementBytes(), dim, mask, terminator, "REDUCE", accumulator); diff --git a/flang/runtime/reduction-templates.h b/flang/runtime/reduction-templates.h index a51404c96376..6b7d57f98384 100644 --- a/flang/runtime/reduction-templates.h +++ b/flang/runtime/reduction-templates.h @@ -321,8 +321,8 @@ RT_VAR_GROUP_BEGIN static constexpr RT_CONST_VAR_ATTRS int Norm2LargestLDKind { #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 16 -#elif LDBL_MANT_DIG == 64 - 10 +#elif HAS_FLOAT80 + 10 #else 8 #endif diff --git a/flang/runtime/sum.cpp b/flang/runtime/sum.cpp index 63d8c9029a0e..88c6c914e1e2 100644 --- a/flang/runtime/sum.cpp +++ b/flang/runtime/sum.cpp @@ -141,18 +141,18 @@ CppTypeFor RTDEF(SumReal8)(const Descriptor &x, return GetTotalReduction( x, source, line, dim, mask, RealSumAccumulator{x}, "SUM"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 CppTypeFor RTDEF(SumReal10)(const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { - return GetTotalReduction( - x, source, line, dim, mask, RealSumAccumulator{x}, "SUM"); + return GetTotalReduction(x, source, line, dim, mask, + RealSumAccumulator>{x}, "SUM"); } #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 CppTypeFor RTDEF(SumReal16)(const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { - return GetTotalReduction( - x, source, line, dim, mask, RealSumAccumulator{x}, "SUM"); + return GetTotalReduction(x, source, line, dim, mask, + RealSumAccumulator>{x}, "SUM"); } #endif @@ -168,20 +168,22 @@ void RTDEF(CppSumComplex8)(CppTypeFor &result, result = GetTotalReduction( x, source, line, dim, mask, ComplexSumAccumulator{x}, "SUM"); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(CppSumComplex10)(CppTypeFor &result, const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { - result = GetTotalReduction( - x, source, line, dim, mask, ComplexSumAccumulator{x}, "SUM"); + result = + GetTotalReduction(x, source, line, dim, mask, + ComplexSumAccumulator>{x}, "SUM"); } #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 void RTDEF(CppSumComplex16)(CppTypeFor &result, const Descriptor &x, const char *source, int line, int dim, const Descriptor *mask) { - result = GetTotalReduction( - x, source, line, dim, mask, ComplexSumAccumulator{x}, "SUM"); + result = + GetTotalReduction(x, source, line, dim, mask, + ComplexSumAccumulator>{x}, "SUM"); } #endif diff --git a/flang/runtime/transformational.cpp b/flang/runtime/transformational.cpp index b6b204be4418..0ce18171274e 100644 --- a/flang/runtime/transformational.cpp +++ b/flang/runtime/transformational.cpp @@ -342,7 +342,7 @@ void RTDEF(BesselJn_8)(Descriptor &result, int32_t n1, int32_t n2, result, n1, n2, x, bn2, bn2_1, sourceFile, line); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(BesselJn_10)(Descriptor &result, int32_t n1, int32_t n2, CppTypeFor x, CppTypeFor bn2, @@ -375,7 +375,7 @@ void RTDEF(BesselJnX0_8)(Descriptor &result, int32_t n1, int32_t n2, DoBesselJnX0(result, n1, n2, sourceFile, line); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(BesselJnX0_10)(Descriptor &result, int32_t n1, int32_t n2, const char *sourceFile, int line) { DoBesselJnX0(result, n1, n2, sourceFile, line); @@ -405,7 +405,7 @@ void RTDEF(BesselYn_8)(Descriptor &result, int32_t n1, int32_t n2, result, n1, n2, x, bn1, bn1_1, sourceFile, line); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(BesselYn_10)(Descriptor &result, int32_t n1, int32_t n2, CppTypeFor x, CppTypeFor bn1, @@ -438,7 +438,7 @@ void RTDEF(BesselYnX0_8)(Descriptor &result, int32_t n1, int32_t n2, DoBesselYnX0(result, n1, n2, sourceFile, line); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 void RTDEF(BesselYnX0_10)(Descriptor &result, int32_t n1, int32_t n2, const char *sourceFile, int line) { DoBesselYnX0(result, n1, n2, sourceFile, line); diff --git a/flang/unittests/Runtime/Numeric.cpp b/flang/unittests/Runtime/Numeric.cpp index 799756aab383..3e574c06b091 100644 --- a/flang/unittests/Runtime/Numeric.cpp +++ b/flang/unittests/Runtime/Numeric.cpp @@ -34,7 +34,7 @@ TEST(Numeric, Floor) { TEST(Numeric, Erfc_scaled) { EXPECT_NEAR(RTNAME(ErfcScaled4)(Real<4>{20.0}), 0.02817434874, 1.0e-8); EXPECT_NEAR(RTNAME(ErfcScaled8)(Real<8>{20.0}), 0.02817434874, 1.0e-11); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 EXPECT_NEAR(RTNAME(ErfcScaled10)(Real<10>{20.0}), 0.02817434874, 1.0e-8); #endif } @@ -295,7 +295,7 @@ TEST(Numeric, FPowI) { EXPECT_EQ(RTNAME(FPow8k)(Real<8>{-3}, Int<8>{3}), Real<8>{-27}); EXPECT_EQ(RTNAME(FPow8k)(Real<8>{-2}, Int<8>{-3}), Real<8>{-0.125}); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 EXPECT_EQ(RTNAME(FPow10i)(Real<10>{0}, Int<4>{0}), Real<10>{1}); EXPECT_EQ(RTNAME(FPow10i)(Real<10>{0.3}, Int<4>{0}), Real<10>{1}); EXPECT_EQ(RTNAME(FPow10i)(Real<10>{2}, Int<4>{-1}), Real<10>{0.5}); diff --git a/flang/unittests/Runtime/Transformational.cpp b/flang/unittests/Runtime/Transformational.cpp index 5836e70c740f..b36ea0a60c67 100644 --- a/flang/unittests/Runtime/Transformational.cpp +++ b/flang/unittests/Runtime/Transformational.cpp @@ -108,7 +108,7 @@ template static void testBesselJnX0(BesselX0FuncType rtFunc) { static void testBesselJn() { testBesselJn<4>(RTNAME(BesselJn_4)); testBesselJn<8>(RTNAME(BesselJn_8)); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 testBesselJn<10>(RTNAME(BesselJn_10)); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -117,7 +117,7 @@ static void testBesselJn() { testBesselJnX0<4>(RTNAME(BesselJnX0_4)); testBesselJnX0<8>(RTNAME(BesselJnX0_8)); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 testBesselJnX0<10>(RTNAME(BesselJnX0_10)); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -201,7 +201,7 @@ template static void testBesselYnX0(BesselX0FuncType rtFunc) { static void testBesselYn() { testBesselYn<4>(RTNAME(BesselYn_4)); testBesselYn<8>(RTNAME(BesselYn_8)); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 testBesselYn<10>(RTNAME(BesselYn_10)); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -210,7 +210,7 @@ static void testBesselYn() { testBesselYnX0<4>(RTNAME(BesselYnX0_4)); testBesselYnX0<8>(RTNAME(BesselYnX0_8)); -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 testBesselYnX0<10>(RTNAME(BesselYnX0_10)); #endif #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 @@ -523,7 +523,7 @@ TEST(Transformational, Unpack) { result.Destroy(); } -#if LDBL_MANT_DIG == 64 +#if HAS_FLOAT80 // Make sure the destination descriptor is created by the runtime // with proper element size, when REAL*10 maps to 'long double'. #define Real10CppType long double