From 9422b5ebc3592f4687650a84131e736219308b9f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 4 Aug 2020 21:37:01 -0700 Subject: QtPrivate::isLatin1: fix SSE2 non-SSE4.1 code The implementation was broken. The "high" in PUNPCKHBW's "unpack high data" means the high 64-bit of the 128-bit, not the high byte of a 16- bit word. This never worked. It always passed for me because I don't build non-SSE4.2 code (too old, no longer relevant). So just use the working version of simdTestMask. Pick-to: 5.15 5.12 Change-Id: I35a1b4d0a19a43149daefffd16284542f0de3fa3 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/text/qstring.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index b63b980e72..82cdeec1a3 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -564,31 +564,12 @@ bool QtPrivate::isLatin1(QStringView s) noexcept const QChar *ptr = s.begin(); const QChar *end = s.end(); -#if defined(__SSE4_1__) +#ifdef __SSE2__ const char *ptr8 = reinterpret_cast(ptr); const char *end8 = reinterpret_cast(end); if (!simdTestMask(ptr8, end8, 0xff00ff00)) return false; ptr = reinterpret_cast(ptr8); -#elif defined(__SSE2__) - // Testing if every other byte is non-zero can be done efficiently by - // using PUNPCKHBW (unpack high order bytes) and comparing that to zero. - while (ptr + 32 < end) { - __m128i data1 = _mm_loadu_si128(reinterpret_cast(ptr)); - __m128i data2 = _mm_loadu_si128(reinterpret_cast(ptr + 16)); - __m128i high = _mm_unpackhi_epi8(data1, data2); - __m128i comparison = _mm_cmpeq_epi16(high, _mm_setzero_si128()); - if (_mm_movemask_epi8(comparison)) - return false; - ptr += 16; - } - if (ptr + 16 < end) { - __m128i data1 = _mm_loadu_si128(reinterpret_cast(ptr)); - __m128i high = _mm_unpackhi_epi8(data1, data1); - __m128i comparison = _mm_cmpeq_epi16(high, _mm_setzero_si128()); - if (_mm_movemask_epi8(comparison)) - return false; - } #endif while (ptr != end) { -- cgit v1.2.3