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/text/qstringconverter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/corelib/text/qstringconverter.cpp') diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp index 84f293ae5f..778674ebd8 100644 --- a/src/corelib/text/qstringconverter.cpp +++ b/src/corelib/text/qstringconverter.cpp @@ -50,6 +50,10 @@ #include #endif +#if __has_include() +#include +#endif + QT_BEGIN_NAMESPACE enum { Endian = 0, Data = 1 }; @@ -60,12 +64,16 @@ static const uchar utf8bom[] = { 0xef, 0xbb, 0xbf }; || (defined(__ARM_NEON__) && defined(Q_PROCESSOR_ARM_64)) static Q_ALWAYS_INLINE uint qBitScanReverse(unsigned v) noexcept { +#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L + return std::bit_width(v) - 1; +#else uint result = qCountLeadingZeroBits(v); // Now Invert the result: clz will count *down* from the msb to the lsb, so the msb index is 31 // and the lsb index is 0. The result for _bit_scan_reverse is expected to be the index when // counting up: msb index is 0 (because it starts there), and the lsb index is 31. result ^= sizeof(unsigned) * 8 - 1; return result; +#endif } #endif -- cgit v1.2.3