From 9eb1eb10c1256448c30f558766d50cbbba54218d Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 26 Sep 2023 17:11:03 +0200 Subject: [PATCH] Move the definition of a native float from qfloat16.h to qtypes.h ... and put it into QtPrivate namespace as NativeFloat16Type. Keep the qfloat16::NativeFloat definition for SC. This is in preparation of Qt::compareThreeWay() for NativeFloat16Type (where available and mis-classified as non-is_floating_point). Amends 99c7f0419e66692260be56c0385badeacb3f6760. Pick-to: 6.5 Task-number: QTBUG-104113 Change-Id: Ie12c42c86f8dc9e233fe39776b0f0e28088de9e2 Reviewed-by: Thiago Macieira Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 43d3d037605bac4e13a1282c4eb363cdee98eb74) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qfloat16.h | 26 +++----------------------- src/corelib/global/qtypes.h | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 15dab5e7139..f342428a334 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -9,15 +9,11 @@ #include #include #include +#include #include #include -#if defined(__STDCPP_FLOAT16_T__) && __has_include() -// P1467 implementation - https://wg21.link/p1467 -# include -#endif - #if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__AVX2__) && !defined(__F16C__) // All processors that support AVX2 do support F16C too, so we could enable the // feature unconditionally if __AVX2__ is defined. However, all currently @@ -55,24 +51,8 @@ class qfloat16 }; public: -#if defined(__STDCPP_FLOAT16_T__) -# define QFLOAT16_IS_NATIVE 1 - using NativeType = std::float16_t; -#elif defined(Q_CC_CLANG) && defined(__FLT16_MAX__) && 0 - // disabled due to https://github.com/llvm/llvm-project/issues/56963 -# define QFLOAT16_IS_NATIVE 1 - using NativeType = decltype(__FLT16_MAX__); -#elif defined(Q_CC_GNU_ONLY) && defined(__FLT16_MAX__) -# define QFLOAT16_IS_NATIVE 1 -# ifdef __ARM_FP16_FORMAT_IEEE - using NativeType = __fp16; -# else - using NativeType = _Float16; -# endif -#else -# define QFLOAT16_IS_NATIVE 0 - using NativeType = void; -#endif + using NativeType = QtPrivate::NativeFloat16Type; + static constexpr bool IsNative = QFLOAT16_IS_NATIVE; using NearestFloat = std::conditional_t; diff --git a/src/corelib/global/qtypes.h b/src/corelib/global/qtypes.h index 41e6025735e..705de1a0883 100644 --- a/src/corelib/global/qtypes.h +++ b/src/corelib/global/qtypes.h @@ -12,6 +12,10 @@ #ifdef __cplusplus # include # include +# if defined(__STDCPP_FLOAT16_T__) && __has_include() +// P1467 implementation - https://wg21.link/p1467 +# include +# endif // defined(__STDCPP_FLOAT16_T__) && __has_include() #else # include #endif @@ -250,6 +254,28 @@ using qsizetype = QIntegerForSizeof::Signed; #error Unsupported platform (unknown value for SIZE_MAX) #endif +// Define a native float16 type +namespace QtPrivate { +#if defined(__STDCPP_FLOAT16_T__) +# define QFLOAT16_IS_NATIVE 1 +using NativeFloat16Type = std::float16_t; +#elif defined(Q_CC_CLANG) && defined(__FLT16_MAX__) && 0 +// disabled due to https://github.com/llvm/llvm-project/issues/56963 +# define QFLOAT16_IS_NATIVE 1 +using NativeFloat16Type = decltype(__FLT16_MAX__); +#elif defined(Q_CC_GNU_ONLY) && defined(__FLT16_MAX__) +# define QFLOAT16_IS_NATIVE 1 +# ifdef __ARM_FP16_FORMAT_IEEE +using NativeFloat16Type = __fp16; +# else +using NativeFloat16Type = _Float16; +# endif +#else +# define QFLOAT16_IS_NATIVE 0 +using NativeFloat16Type = void; +#endif +} // QtPrivate + #endif // __cplusplus QT_END_NAMESPACE