I got around to reviewing this and noticed one minor problem: the code will mistakenly reject an implementation that (say) has a 72-bit word but where 8 bits are padding bits, i.e., they do not contribute to the value. This sort of trick used to be played (and perhaps still is played; I don't know) on Unisys mainframes, and C99 allows such implementations. For this code, it's easy to be portable even to these weird systems so we might as well do it that way.
Here's an (untested) patch to do this. This patch also implement's Bruno's suggestion to use 'verify' rather than 'verify_true'. 2007-08-14 Paul Eggert <[EMAIL PROTECTED]> * 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. --- lib/count-one-bits.h 24 Jul 2007 20:13:20 -0700 1.1 +++ lib/count-one-bits.h 14 Aug 2007 11:43:59 -0700 @@ -20,7 +20,6 @@ #ifndef COUNT_ONE_BITS_H # define COUNT_ONE_BITS_H 1 -#include <limits.h> #include <stdlib.h> #include "verify.h" @@ -29,10 +28,10 @@ return BUILTIN (x); #else #define COUNT_ONE_BITS(BUILTIN, TYPE) \ + verify ((TYPE) -1 >> 31 >> 31 <= 3); \ int count = count_one_bits_32 (x); \ - if (CHAR_BIT * sizeof (TYPE) > 32) \ + if (1 < (TYPE) -1 >> 31) \ count += count_one_bits_32 (x >> 31 >> 1); \ - (void) verify_true (CHAR_BIT * sizeof (TYPE) <= 64); \ return count; /* Compute and return the the number of 1-bits set in the least