1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

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.
This commit is contained in:
Paul Eggert
2015-07-21 22:50:29 -07:00
parent 1814df5b02
commit 5542236837
5 changed files with 19 additions and 32 deletions

View File

@@ -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> 2015-08-18 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/x86/cpu-features.c (init_cpu_features): Check * sysdeps/x86/cpu-features.c (init_cpu_features): Check

View File

@@ -96,15 +96,8 @@ MEMRCHR
The 1-bits make sure that carries propagate to the next 0-bit. The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */ The 0-bits provide holes for carries to fall into. */
magic_bits = -1;
if (sizeof (longword) != 4 && sizeof (longword) != 8) magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
abort ();
#if LONG_MAX <= LONG_MAX_32_BITS
magic_bits = 0x7efefeff;
#else
magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
#endif
/* Set up a longword, each of whose bytes is C. */ /* Set up a longword, each of whose bytes is C. */
charmask = c | (c << 8); charmask = c | (c << 8);

View File

@@ -86,15 +86,8 @@ RAWMEMCHR (s, c_in)
The 1-bits make sure that carries propagate to the next 0-bit. The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */ The 0-bits provide holes for carries to fall into. */
magic_bits = -1;
if (sizeof (longword) != 4 && sizeof (longword) != 8) magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
abort ();
#if LONG_MAX <= LONG_MAX_32_BITS
magic_bits = 0x7efefeff;
#else
magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
#endif
/* Set up a longword, each of whose bytes is C. */ /* Set up a longword, each of whose bytes is C. */
charmask = c | (c << 8); charmask = c | (c << 8);

View 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 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */ The 0-bits provide holes for carries to fall into. */
switch (sizeof (longword)) magic_bits = -1;
{ magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
case 4: magic_bits = 0x7efefeffL; break;
case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
default:
abort ();
}
/* Set up a longword, each of whose bytes is C. */ /* Set up a longword, each of whose bytes is C. */
charmask = c | (c << 8); charmask = c | (c << 8);

View File

@@ -66,13 +66,8 @@ STRCHRNUL (s, c_in)
The 1-bits make sure that carries propagate to the next 0-bit. The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */ The 0-bits provide holes for carries to fall into. */
switch (sizeof (longword)) magic_bits = -1;
{ magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1;
case 4: magic_bits = 0x7efefeffL; break;
case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
default:
abort ();
}
/* Set up a longword, each of whose bytes is C. */ /* Set up a longword, each of whose bytes is C. */
charmask = c | (c << 8); charmask = c | (c << 8);