From e70324f8dd1f191556599cf60100dd0ad0b16708 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 3 Dec 2015 12:50:44 +0100 Subject: Remove _bit_scan_{forward,reverse} Use qCountTrailingZeroBits and qCountLeadingZeroBits from qalgorithms.h instead. Also extended these versions for MSVC. The _bit_scan_* versions stem from a time before the glorious days of qalgorithms.h. A big advantage is that these functions can be used on all platforms. Change-Id: I5a1b886371520310a7fe16e617635ea335046beb Reviewed-by: Simon Hausmann --- src/corelib/codecs/qutfcodec.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/corelib/codecs/qutfcodec.cpp') diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index f1054ceb98..b4bc1583e6 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -53,6 +53,16 @@ enum { Endian = 0, Data = 1 }; static const uchar utf8bom[] = { 0xef, 0xbb, 0xbf }; #if defined(__SSE2__) && defined(QT_COMPILER_SUPPORTS_SSE2) +static Q_ALWAYS_INLINE uint qBitScanReverse(unsigned v) Q_DECL_NOTHROW +{ + 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; +} + static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const ushort *&src, const ushort *end) { // do sixteen characters at a time @@ -81,9 +91,9 @@ static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const // find the next probable ASCII character // we don't want to load 32 bytes again in this loop if we know there are non-ASCII // characters still coming - nextAscii = src + _bit_scan_reverse(n) + 1; + nextAscii = src + qBitScanReverse(n) + 1; - n = _bit_scan_forward(n); + n = qCountTrailingZeroBits(n); dst += n; src += n; return false; @@ -132,7 +142,7 @@ static inline bool simdDecodeAscii(ushort *&dst, const uchar *&nextAscii, const // find the next probable ASCII character // we don't want to load 16 bytes again in this loop if we know there are non-ASCII // characters still coming - n = _bit_scan_reverse(n); + n = qBitScanReverse(n); nextAscii = src + (n / BitSpacing) + 1; return false; -- cgit v1.2.3