summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@gnu.org>2007-08-15 03:37:54 +0000
committerBen Pfaff <blp@gnu.org>2007-08-15 03:37:54 +0000
commit6684d992bfedd21bf8dea1fbb52392c1d7c8159b (patch)
tree4d9507b4b9c43b766795921d329434407a68f85d
parent50236f7a99ae6442f6235451da1e345ca0fe7b18 (diff)
downloadgnulib-6684d992bfedd21bf8dea1fbb52392c1d7c8159b.tar.gz
* lib/count-one-bits.h: Add comments. (From Bruno Haible.)
* lib/count-one-bits.h: Don't include <limits.h>; no longer needed given the changes below. (COUNT_ONE_BITS): Use 'verify' rather than 'verify_true'. Work even on hosts that have padding bits beyond the supported 64. (From Paul Eggert.)
-rw-r--r--ChangeLog11
-rw-r--r--lib/count-one-bits.h14
2 files changed, 19 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 38652ba833..db8ece63b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-08-14 Ben Pfaff <blp@gnu.org>
+
+ * lib/count-one-bits.h: Add comments. From Bruno Haible.
+
+2007-08-14 Paul Eggert <eggert@cs.ucla.edu>
+
+ * lib/count-one-bits.h: Don't include <limits.h>; no longer needed
+ given the changes below.
+ (COUNT_ONE_BITS): Use 'verify' rather than 'verify_true'. Work
+ even on hosts that have padding bits beyond the supported 64.
+
2007-08-10 Paul Eggert <eggert@cs.ucla.edu>
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h
index 7553bec4ec..e4a477b19d 100644
--- a/lib/count-one-bits.h
+++ b/lib/count-one-bits.h
@@ -20,19 +20,21 @@
#ifndef COUNT_ONE_BITS_H
# define COUNT_ONE_BITS_H 1
-#include <limits.h>
#include <stdlib.h>
#include "verify.h"
+/* Expand the code which computes the number of 1-bits of the local
+ variable 'x' of type TYPE (an unsigned integer type) and returns it
+ from the current function. */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR >= 4)
#define COUNT_ONE_BITS(BUILTIN, TYPE) \
return BUILTIN (x);
#else
-#define COUNT_ONE_BITS(BUILTIN, TYPE) \
- int count = count_one_bits_32 (x); \
- if (CHAR_BIT * sizeof (TYPE) > 32) \
- count += count_one_bits_32 (x >> 31 >> 1); \
- (void) verify_true (CHAR_BIT * sizeof (TYPE) <= 64); \
+#define COUNT_ONE_BITS(BUILTIN, TYPE) \
+ verify ((TYPE) -1 >> 31 >> 31 <= 3); /* TYPE has at most 64 bits */ \
+ int count = count_one_bits_32 (x); \
+ if (1 < (TYPE) -1 >> 31) /* TYPE has more than 32 bits? */ \
+ count += count_one_bits_32 (x >> 31 >> 1); \
return count;
/* Compute and return the the number of 1-bits set in the least