From 3f6f4e65e7806fd49137cf3cf59a1432ed776b2a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 22 Nov 2011 18:56:46 +0000 Subject: [PATCH] Lexer: Don't throw away the hard work SSE did to find a slash. We can reuse the information and avoid looping over all the bytes again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145070 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/Lexer.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 796110a34f..a115579843 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1916,11 +1916,18 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) { if (C == '/') goto FoundSlash; #ifdef __SSE2__ - __m128i Slashes = _mm_set_epi8('/', '/', '/', '/', '/', '/', '/', '/', - '/', '/', '/', '/', '/', '/', '/', '/'); - while (CurPtr+16 <= BufferEnd && - _mm_movemask_epi8(_mm_cmpeq_epi8(*(__m128i*)CurPtr, Slashes)) == 0) + __m128i Slashes = _mm_set1_epi8('/'); + while (CurPtr+16 <= BufferEnd) { + int cmp = _mm_movemask_epi8(_mm_cmpeq_epi8(*(__m128i*)CurPtr, Slashes)); + if (cmp != 0) { + // Adjust the pointer to the first '/' that was found. + CurPtr += llvm::CountTrailingZeros_32(cmp); + C = *CurPtr++; + assert(C == '/'); + goto FoundSlash; + } CurPtr += 16; + } #elif __ALTIVEC__ __vector unsigned char Slashes = { '/', '/', '/', '/', '/', '/', '/', '/', @@ -1948,8 +1955,8 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) { while (C != '/' && C != '\0') C = *CurPtr++; - FoundSlash: if (C == '/') { + FoundSlash: if (CurPtr[-2] == '*') // We found the final */. We're done! break; -- 2.40.0