From 3b528670e6d5cbe25e0892b484b3e93417e263d3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 12 Jan 2022 19:56:32 -0800 Subject: QString::toLatin1/SSE: simplify the code to merge question marks Just move the test of Checked into the lambda, so we can call it unconditionally. Change-Id: I0e5f6bec596a4a78bd3bfffd16c9b84ff4a31bb9 Reviewed-by: Marc Mutz --- src/corelib/text/qstring.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 49e26d7615..90e791d0d3 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -884,6 +884,9 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len } auto mergeQuestionMarks = [=](__m128i chunk) { + if (!Checked) + return chunk; + // SSE has no compare instruction for unsigned comparison. if constexpr (UseSse4_1) { // We use an unsigned uc = qMin(uc, 0x100) and then compare for equality. @@ -930,12 +933,10 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len chunk1 = _mm256_castsi256_si128(chunk); } else { chunk1 = _mm_loadu_si128((const __m128i*)(src + offset)); // load - if (Checked) - chunk1 = mergeQuestionMarks(chunk1); + chunk1 = mergeQuestionMarks(chunk1); chunk2 = _mm_loadu_si128((const __m128i*)(src + offset + 8)); // load - if (Checked) - chunk2 = mergeQuestionMarks(chunk2); + chunk2 = mergeQuestionMarks(chunk2); } // pack the two vector to 16 x 8bits elements @@ -947,8 +948,7 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len // we're going to write to dst[offset..offset+7] (8 bytes) if (dst + offset + 7 < e) { __m128i chunk = _mm_loadu_si128(reinterpret_cast(src + offset)); - if (Checked) - chunk = mergeQuestionMarks(chunk); + chunk = mergeQuestionMarks(chunk); // pack, where the upper half is ignored const __m128i result = _mm_packus_epi16(chunk, chunk); @@ -959,8 +959,7 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len // we're going to write to dst[offset..offset+3] (4 bytes) if (dst + offset + 3 < e) { __m128i chunk = _mm_loadl_epi64(reinterpret_cast(src + offset)); - if (Checked) - chunk = mergeQuestionMarks(chunk); + chunk = mergeQuestionMarks(chunk); // pack, we'll the upper three quarters const __m128i result = _mm_packus_epi16(chunk, chunk); -- cgit v1.2.3