[cfe-commits] r145070 - /cfe/trunk/lib/Lex/Lexer.cpp

Benjamin Kramer benny.kra at googlemail.com
Tue Nov 22 12:41:54 PST 2011


On 22.11.2011, at 20:50, Eli Friedman wrote:

> On Tue, Nov 22, 2011 at 10:56 AM, Benjamin Kramer
> <benny.kra at googlemail.com> wrote:
>> Author: d0k
>> Date: Tue Nov 22 12:56:46 2011
>> New Revision: 145070
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=145070&view=rev
>> Log:
>> 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.
> 
> What effect on performance does this change have?

I saw about 0.5% speedup with -Eonly on all of /usr/include on a Debian box (Release build). The increase would probably be bigger if LLVM was smarter at codegenning __builtin_ctz.

- Ben

> 
> -Eli
> 
>> Modified:
>>    cfe/trunk/lib/Lex/Lexer.cpp
>> 
>> Modified: cfe/trunk/lib/Lex/Lexer.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=145070&r1=145069&r2=145070&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Lex/Lexer.cpp (original)
>> +++ cfe/trunk/lib/Lex/Lexer.cpp Tue Nov 22 12:56:46 2011
>> @@ -1916,11 +1916,18 @@
>>       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 @@
>>     while (C != '/' && C != '\0')
>>       C = *CurPtr++;
>> 
>> -  FoundSlash:
>>     if (C == '/') {
>> +  FoundSlash:
>>       if (CurPtr[-2] == '*')  // We found the final */.  We're done!
>>         break;
>> 
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> 





More information about the cfe-commits mailing list