diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-08-08 12:52:36 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-13 18:26:49 +0200 |
commit | 6a37ca39ec7cfc2f4392784fd31936526d55e941 (patch) | |
tree | 240d1a2034b87a0094b0fc96a07a46e3a3b0902b /src/corelib/text/qstringconverter.cpp | |
parent | 65afcef2173cabe297778d19dda3198595820cfa (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qstringconverter.cpp')
-rw-r--r-- | src/corelib/text/qstringconverter.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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 <qt_windows.h> #endif +#if __has_include(<bit>) +#include <bit> +#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 |