From 5dd0b42b6ea96882ce31a0df9e6420bfc4eea6e9 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sun, 11 Nov 2018 22:59:33 -0800 Subject: [PATCH] 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. --- src/microcode/bits.h | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) 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 \ -- 2.25.1