about summary refs log tree commit diff
path: root/sysdeps/x86_64
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-10-28 18:18:04 -0400
committerUlrich Drepper <drepper@gmail.com>2011-10-28 18:18:04 -0400
commitfd52bc6dc4bfb844995cc63d98682970de1c9fed (patch)
treec60b3af259981ba8275c7891248c890a474f0123 /sysdeps/x86_64
parenta5b81e1fb7c6a5e323785598767460fe040ca778 (diff)
downloadglibc-fd52bc6dc4bfb844995cc63d98682970de1c9fed.tar.gz
glibc-fd52bc6dc4bfb844995cc63d98682970de1c9fed.tar.xz
glibc-fd52bc6dc4bfb844995cc63d98682970de1c9fed.zip
Clean up x86-64 strcasestr
Actually describe in the C code what is going on.
Diffstat (limited to 'sysdeps/x86_64')
-rw-r--r--sysdeps/x86_64/multiarch/strstr.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/sysdeps/x86_64/multiarch/strstr.c b/sysdeps/x86_64/multiarch/strstr.c
index b408b752fa..6e93744140 100644
--- a/sysdeps/x86_64/multiarch/strstr.c
+++ b/sysdeps/x86_64/multiarch/strstr.c
@@ -1,5 +1,5 @@
 /* strstr with SSE4.2 intrinsics
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
    Contributed by Intel Corporation.
    This file is part of the GNU C Library.
 
@@ -106,24 +106,22 @@ __m128i_strloadu (const unsigned char * p)
 #if defined USE_AS_STRCASESTR && !defined STRCASESTR_NONASCII
 
 /* Similar to __m128i_strloadu.  Convert to lower case for POSIX/C
-   locale.  */
+   locale and other which have single-byte letters only in the ASCII
+   range.  */
 static inline __m128i
-__m128i_strloadu_tolower (const unsigned char *p, __m128i rangeuc,
-			  __m128i u2ldelta)
+__m128i_strloadu_tolower (const unsigned char *p, __m128i uclow,
+			  __m128i uchigh, __m128i lcqword)
 {
   __m128i frag = __m128i_strloadu (p);
 
-#define UCLOW 0x4040404040404040ULL
-#define UCHIGH 0x5b5b5b5b5b5b5b5bULL
-#define LCQWORD 0x2020202020202020ULL
   /* Compare if 'Z' > bytes. Inverted way to get a mask for byte <= 'Z'.  */
-  __m128i r2 = _mm_cmpgt_epi8 (_mm_set1_epi64x (UCHIGH), frag);
+  __m128i r2 = _mm_cmpgt_epi8 (uchigh, frag);
   /* Compare if bytes are > 'A' - 1.  */
-  __m128i r1 = _mm_cmpgt_epi8 (frag, _mm_set1_epi64x (UCLOW));
+  __m128i r1 = _mm_cmpgt_epi8 (frag, uclow);
   /* Mask byte == ff if byte(r2) <= 'Z' and byte(r1) > 'A' - 1.  */
   __m128i mask = _mm_and_si128 (r2, r1);
   /* Apply lowercase bit 6 mask for above mask bytes == ff.  */
-  return _mm_or_si128 (frag, _mm_and_si128 (mask, _mm_set1_epi64x (LCQWORD)));
+  return _mm_or_si128 (frag, _mm_and_si128 (mask, lcqword));
 }
 
 #endif
@@ -190,9 +188,10 @@ STRSTR_SSE42 (const unsigned char *s1, const unsigned char *s2)
 			!= 0, 0))
     return __strcasestr_sse42_nonascii (s1, s2);
 
-  const __m128i rangeuc = _mm_set_epi64x (0x0, 0x5a41);
-  const __m128i u2ldelta = _mm_set1_epi64x (0xe0e0e0e0e0e0e0e0);
-#  define strloadu(p) __m128i_strloadu_tolower (p, rangeuc, u2ldelta)
+  const __m128i uclow = _mm_set1_epi8 (0x40);
+  const __m128i uchigh = _mm_set1_epi8 (0x5b);
+  const __m128i lcqword = _mm_set1_epi8 (0x20);
+#  define strloadu(p) __m128i_strloadu_tolower (p, uclow, uchigh, lcqword)
 # else
 #  define strloadu __m128i_strloadu_tolower
 # endif