]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Port the 0x7efe...feff pattern to GCC 6.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 22 Jul 2015 05:50:29 +0000 (22:50 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 18 Aug 2015 17:00:57 +0000 (10:00 -0700)
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.

ChangeLog
string/memrchr.c
string/rawmemchr.c
string/strchr.c
string/strchrnul.c

index db5d4831807e6a741a443ee7f1893c5f34d9c697..bfc31fc8f798640913121c800c33501e6a464649 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-08-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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.
+
 2015-08-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        * sysdeps/x86/cpu-features.c (init_cpu_features): Check
index 0c8fd84901a35503834eea47c6111231c3766832..86cd5b970cd1507bb5996fc4318d4e5b909cba52 100644 (file)
@@ -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);
index 05b22be24e53755a4cb4e85a694f62ec63e0c58d..228ca9d216d2361825f6a91f1870b6000fe5baef 100644 (file)
@@ -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);
index 5f900750a3aee553f6af3fbced634fc440bee6e4..f13b2b3d94c7db1c1c7b01cfc12786f8ffeb672a 100644 (file)
@@ -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);
index 2678f1de0a7142fa6f69713576eaebcfcd9ffcaf..daf0b3f659d6d0e9bfb3c79448f3d9593bfbe8ba 100644 (file)
@@ -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);