From 543aa4bf21b169a48e5c3164ddd453e99e83d4ee Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 19 Mar 2011 16:40:23 +0100 Subject: Improve the code and avoid unnecessary stores If there's an UTF-8 high byte in the first 8 bytes, don't try to save the latter 8 characters --- tests/benchmarks/corelib/tools/qstring/main.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp index e05915d..39c9739 100644 --- a/tests/benchmarks/corelib/tools/qstring/main.cpp +++ b/tests/benchmarks/corelib/tools/qstring/main.cpp @@ -2068,19 +2068,21 @@ int fromUtf8_sse2_optimised_for_ascii(ushort *qch, const char *chars, int len) const __m128i nullMask = _mm_set1_epi32(0); while (counter < len) { const __m128i chunk = _mm_loadu_si128((__m128i*)(chars + counter)); // load + ushort highbytes = _mm_movemask_epi8(chunk); // unpack the first 8 bytes, padding with zeros const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask); _mm_storeu_si128((__m128i*)(dst + counter), firstHalf); // store - // unpack the last 8 bytes, padding with zeros - const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask); - _mm_storeu_si128((__m128i*)(dst + counter + 8), secondHalf); // store + if (!uchar(highbytes)) { + // unpack the last 8 bytes, padding with zeros + const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask); + _mm_storeu_si128((__m128i*)(dst + counter + 8), secondHalf); // store - ushort highbytes = _mm_movemask_epi8(chunk); - if (!highbytes) { - counter += 16; - continue; + if (!highbytes) { + counter += 16; + continue; + } } // UTF-8 character found -- cgit v0.12