From c780434ba24ff28bc8a19c2a6145c02b703336a7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 16 May 2018 13:54:56 -0700 Subject: [PATCH] qt_is_ascii: improve isAscii a little further (QUrl, QLatin1String) Turns out that the non-AVX2 code was beating the performance of the AVX2 because the simdTestMask function did a little too much. So just use the same VPMOVMSKB technique for it. Change-Id: I0825ff5b5f6f4c85939ffffd152f3b636ab998db Reviewed-by: Allan Sandfeld Jensen --- src/corelib/tools/qstring.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index bcc94e260a2..a4b34263df8 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -311,12 +311,19 @@ bool QtPrivate::isAscii(QLatin1String s) Q_DECL_NOTHROW const char *ptr = s.begin(); const char *end = s.end(); -#if defined(__AVX2__) - if (!simdTestMask(ptr, end, 0x80808080)) - return false; -#elif defined(__SSE2__) +#if defined(__SSE2__) // Testing for the high bit can be done efficiently with just PMOVMSKB - while (ptr + 16 < end) { +# if defined(__AVX2__) + while (ptr + 32 <= end) { + __m256i data = _mm256_loadu_si256(reinterpret_cast(ptr)); + quint32 mask = _mm256_movemask_epi8(data); + if (mask) + return false; + ptr += 32; + } +# endif + + while (ptr + 16 <= end) { __m128i data = _mm_loadu_si128(reinterpret_cast(ptr)); quint32 mask = _mm_movemask_epi8(data); if (mask)