mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-25 04:01:10 +00:00
Copy regex BITSET_WORD_BITS porting from Gnulib
* posix/regex.c (__STDC_WANT_IEC_60559_BFP_EXT__): Define, for ULONG_WIDTH. This syncs regex.c from Gnujlib. * posix/regex_internal.h (ULONG_WIDTH): Use a more-portable fallback, from Gnulib. (BITSET_WORD_BITS): Now defined in terms of ULONG_WIDTH.
This commit is contained in:
parent
6aa1160d16
commit
70c609f303
@ -17,6 +17,8 @@
|
|||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#define __STDC_WANT_IEC_60559_BFP_EXT__
|
||||||
|
|
||||||
#ifndef _LIBC
|
#ifndef _LIBC
|
||||||
# include <libc-config.h>
|
# include <libc-config.h>
|
||||||
|
|
||||||
|
@ -141,6 +141,24 @@
|
|||||||
#ifndef SSIZE_MAX
|
#ifndef SSIZE_MAX
|
||||||
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ULONG_WIDTH
|
||||||
|
# define ULONG_WIDTH REGEX_UINTEGER_WIDTH (ULONG_MAX)
|
||||||
|
/* The number of usable bits in an unsigned integer type with maximum
|
||||||
|
value MAX, as an int expression suitable in #if. Cover all known
|
||||||
|
practical hosts. This implementation exploits the fact that MAX is
|
||||||
|
1 less than a power of 2, and merely counts the number of 1 bits in
|
||||||
|
MAX; "COBn" means "count the number of 1 bits in the low-order n bits". */
|
||||||
|
# define REGEX_UINTEGER_WIDTH(max) REGEX_COB128 (max)
|
||||||
|
# define REGEX_COB128(n) (REGEX_COB64 ((n) >> 31 >> 31 >> 2) + REGEX_COB64 (n))
|
||||||
|
# define REGEX_COB64(n) (REGEX_COB32 ((n) >> 31 >> 1) + REGEX_COB32 (n))
|
||||||
|
# define REGEX_COB32(n) (REGEX_COB16 ((n) >> 16) + REGEX_COB16 (n))
|
||||||
|
# define REGEX_COB16(n) (REGEX_COB8 ((n) >> 8) + REGEX_COB8 (n))
|
||||||
|
# define REGEX_COB8(n) (REGEX_COB4 ((n) >> 4) + REGEX_COB4 (n))
|
||||||
|
# define REGEX_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + ((n) & 1))
|
||||||
|
# if ULONG_MAX / 2 + 1 != 1ul << (ULONG_WIDTH - 1)
|
||||||
|
# error "ULONG_MAX out of range"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The type of indexes into strings. This is signed, not size_t,
|
/* The type of indexes into strings. This is signed, not size_t,
|
||||||
since the API requires indexes to fit in regoff_t anyway, and using
|
since the API requires indexes to fit in regoff_t anyway, and using
|
||||||
@ -164,36 +182,8 @@ typedef __re_size_t re_hashval_t;
|
|||||||
typedef unsigned long int bitset_word_t;
|
typedef unsigned long int bitset_word_t;
|
||||||
/* All bits set in a bitset_word_t. */
|
/* All bits set in a bitset_word_t. */
|
||||||
#define BITSET_WORD_MAX ULONG_MAX
|
#define BITSET_WORD_MAX ULONG_MAX
|
||||||
|
/* Number of bits in a bitset_word_t. */
|
||||||
/* Number of bits in a bitset_word_t. For portability to hosts with
|
#define BITSET_WORD_BITS ULONG_WIDTH
|
||||||
padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
|
|
||||||
instead, deduce it directly from BITSET_WORD_MAX. Avoid
|
|
||||||
greater-than-32-bit integers and unconditional shifts by more than
|
|
||||||
31 bits, as they're not portable. */
|
|
||||||
#if BITSET_WORD_MAX == 0xffffffffUL
|
|
||||||
# define BITSET_WORD_BITS 32
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 4 == 1
|
|
||||||
# define BITSET_WORD_BITS 36
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 16 == 1
|
|
||||||
# define BITSET_WORD_BITS 48
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 28 == 1
|
|
||||||
# define BITSET_WORD_BITS 60
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
|
|
||||||
# define BITSET_WORD_BITS 64
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
|
|
||||||
# define BITSET_WORD_BITS 72
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
|
|
||||||
# define BITSET_WORD_BITS 128
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
|
|
||||||
# define BITSET_WORD_BITS 256
|
|
||||||
#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
|
|
||||||
# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
|
|
||||||
# if BITSET_WORD_BITS <= SBC_MAX
|
|
||||||
# error "Invalid SBC_MAX"
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# error "Add case for new bitset_word_t size"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Number of bitset_word_t values in a bitset_t. */
|
/* Number of bitset_word_t values in a bitset_t. */
|
||||||
#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
|
#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
|
||||||
|
Loading…
Reference in New Issue
Block a user