From 6a37ca39ec7cfc2f4392784fd31936526d55e941 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sat, 8 Aug 2020 12:52:36 +0200 Subject: Use universal C++20 bit operations when available Avoids using compiler builtins, and can in future replace them. Change-Id: I3f0afe7d28b6ba05bcd1c1132b44a8db7b182d8a Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmath.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib/kernel/qmath.h') diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index 5f36de303c..4c5a980f3a 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -47,6 +47,10 @@ #include #include +#if __has_include() +#include +#endif + #ifndef _USE_MATH_DEFINES # define _USE_MATH_DEFINES # define undef_USE_MATH_DEFINES @@ -298,7 +302,9 @@ constexpr inline quint64 qConstexprNextPowerOfTwo(qint64 v) constexpr inline quint32 qNextPowerOfTwo(quint32 v) { -#if defined(QT_HAS_BUILTIN_CLZ) +#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L + return std::bit_ceil(v + 1); +#elif defined(QT_HAS_BUILTIN_CLZ) if (v == 0) return 1; return 2U << (31 ^ QAlgorithmsPrivate::qt_builtin_clz(v)); @@ -309,7 +315,9 @@ constexpr inline quint32 qNextPowerOfTwo(quint32 v) constexpr inline quint64 qNextPowerOfTwo(quint64 v) { -#if defined(QT_HAS_BUILTIN_CLZLL) +#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L + return std::bit_ceil(v + 1); +#elif defined(QT_HAS_BUILTIN_CLZLL) if (v == 0) return 1; return Q_UINT64_C(2) << (63 ^ QAlgorithmsPrivate::qt_builtin_clzll(v)); -- cgit v1.2.3