From: Chris Hanson Date: Mon, 12 Nov 2018 06:59:33 +0000 (-0800) Subject: Fix bug: -Werror means FOO_length_in_bits won't compile on 32-bit gcc. X-Git-Tag: mit-scheme-pucked-10.1.2~16^2~108 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=5dd0b42b6ea96882ce31a0df9e6420bfc4eea6e9;p=mit-scheme.git Fix bug: -Werror means FOO_length_in_bits won't compile on 32-bit gcc. Before it just issued a warning. I rewrote it so that it works. --- diff --git a/src/microcode/bits.h b/src/microcode/bits.h index ccd7d0be3..27d7e6975 100644 --- a/src/microcode/bits.h +++ b/src/microcode/bits.h @@ -76,29 +76,44 @@ NAME (TYPE x) \ DEFINE_BIT_COUNT (uintmax_bit_count, uintmax_t) DEFINE_BIT_COUNT (ulong_bit_count, unsigned long) -#define DEFINE_LENGTH_IN_BITS(NAME, TYPE, BIT_COUNT) \ -static inline unsigned int \ -NAME (TYPE x) \ -{ \ +#define LENGTH_IN_BITS_32(TYPE_SIZE) \ /* Round up to a power of two minus one; i.e., set all bits in x \ below and including its most significant set bit. */ \ - int i, limit = (CHAR_BIT * (sizeof (TYPE))); \ - /* Unrolling this loop substantially improves performance. The `for' \ - at the end is for completeness; a good compiler should realize \ - that it is dead code on just about any system. */ \ + int limit = (CHAR_BIT * (TYPE_SIZE)); \ + /* Unrolling this loop substantially improves performance. */ \ if (1 < limit) x |= (x >> 1); \ if (2 < limit) x |= (x >> 2); \ if (4 < limit) x |= (x >> 4); \ if (8 < limit) x |= (x >> 8); \ - if (0x10 < limit) x |= (x >> 0x10); \ + if (0x10 < limit) x |= (x >> 0x10); + +#define LENGTH_IN_BITS_64 \ if (0x20 < limit) x |= (x >> 0x20); \ + /* This `for' loop is for completeness; a good compiler should \ + realize that it is dead code on just about any system. */ \ + int i; \ for (i = 0x40; i < limit; i <<= 1) \ - x |= (x >> i); \ - return (BIT_COUNT (x)); \ + x |= (x >> i); + +static inline unsigned int +ulong_length_in_bits (unsigned long x) +{ + LENGTH_IN_BITS_32(SIZEOF_UNSIGNED_LONG) +#if (SIZEOF_UNSIGNED_LONG >= 8) + LENGTH_IN_BITS_64 +#endif + return (ulong_bit_count (x)); } -DEFINE_LENGTH_IN_BITS (uintmax_length_in_bits, uintmax_t, uintmax_bit_count) -DEFINE_LENGTH_IN_BITS (ulong_length_in_bits, unsigned long, ulong_bit_count) +static inline unsigned int +uintmax_length_in_bits (uintmax_t x) +{ + LENGTH_IN_BITS_32(SIZEOF_UINTMAX_T) +#if (SIZEOF_UINTMAX_T >= 8) + LENGTH_IN_BITS_64 +#endif + return (uintmax_bit_count (x)); +} #define DEFINE_FIRST_SET_BIT(NAME, TYPE, LENGTH_IN_BITS) \ static inline int \