about summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-07-21 22:50:29 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-08-18 10:00:57 -0700
commit5542236837c5c41435f8282ec92799f480c36f18 (patch)
tree9379c73ad00dc1ffea986464bbf96634f3a7fd5f /string
parent1814df5b02b9c359052c2048a1d2d617b406a17a (diff)
downloadglibc-5542236837c5c41435f8282ec92799f480c36f18.tar.gz
glibc-5542236837c5c41435f8282ec92799f480c36f18.tar.xz
glibc-5542236837c5c41435f8282ec92799f480c36f18.zip
Port the 0x7efe...feff pattern to GCC 6.
See Steve Ellcey's bug report in:
https://sourceware.org/ml/libc-alpha/2015-07/msg00673.html
* string/memrchr.c (MEMRCHR):
* string/rawmemchr.c (RAWMEMCHR):
* string/strchr.c (strchr):
* string/strchrnul.c (STRCHRNUL):
Rewrite code to avoid issues with signed shift overflow.
Diffstat (limited to 'string')
-rw-r--r--string/memrchr.c11
-rw-r--r--string/rawmemchr.c11
-rw-r--r--string/strchr.c9
-rw-r--r--string/strchrnul.c9
4 files changed, 8 insertions, 32 deletions
diff --git a/string/memrchr.c b/string/memrchr.c
index 0c8fd84901..86cd5b970c 100644
--- a/string/memrchr.c
+++ b/string/memrchr.c
@@ -96,15 +96,8 @@ MEMRCHR
 
      The 1-bits make sure that carries propagate to the next 0-bit.
      The 0-bits provide holes for carries to fall into.  */
-
-  if (sizeof (longword) != 4 && sizeof (longword) != 8)
-    abort ();
-
-#if LONG_MAX <= LONG_MAX_32_BITS
-  magic_bits = 0x7efefeff;
-#else
-  magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
-#endif
+  magic_bits = -1;
+  magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
 
   /* Set up a longword, each of whose bytes is C.  */
   charmask = c | (c << 8);
diff --git a/string/rawmemchr.c b/string/rawmemchr.c
index 05b22be24e..228ca9d216 100644
--- a/string/rawmemchr.c
+++ b/string/rawmemchr.c
@@ -86,15 +86,8 @@ RAWMEMCHR (s, c_in)
 
      The 1-bits make sure that carries propagate to the next 0-bit.
      The 0-bits provide holes for carries to fall into.  */
-
-  if (sizeof (longword) != 4 && sizeof (longword) != 8)
-    abort ();
-
-#if LONG_MAX <= LONG_MAX_32_BITS
-  magic_bits = 0x7efefeff;
-#else
-  magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
-#endif
+  magic_bits = -1;
+  magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
 
   /* Set up a longword, each of whose bytes is C.  */
   charmask = c | (c << 8);
diff --git a/string/strchr.c b/string/strchr.c
index 5f900750a3..f13b2b3d94 100644
--- a/string/strchr.c
+++ b/string/strchr.c
@@ -60,13 +60,8 @@ strchr (const char *s, int c_in)
 
      The 1-bits make sure that carries propagate to the next 0-bit.
      The 0-bits provide holes for carries to fall into.  */
-  switch (sizeof (longword))
-    {
-    case 4: magic_bits = 0x7efefeffL; break;
-    case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
-    default:
-      abort ();
-    }
+  magic_bits = -1;
+  magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
 
   /* Set up a longword, each of whose bytes is C.  */
   charmask = c | (c << 8);
diff --git a/string/strchrnul.c b/string/strchrnul.c
index 2678f1de0a..daf0b3f659 100644
--- a/string/strchrnul.c
+++ b/string/strchrnul.c
@@ -66,13 +66,8 @@ STRCHRNUL (s, c_in)
 
      The 1-bits make sure that carries propagate to the next 0-bit.
      The 0-bits provide holes for carries to fall into.  */
-  switch (sizeof (longword))
-    {
-    case 4: magic_bits = 0x7efefeffL; break;
-    case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
-    default:
-      abort ();
-    }
+  magic_bits = -1;
+  magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
 
   /* Set up a longword, each of whose bytes is C.  */
   charmask = c | (c << 8);