- register unsigned long tmp;
- return (tmp = (n) - (((n) >> 1) & 033333333333) - (((n) >> 2) & 011111111111),\
- tmp = ((tmp + (tmp >> 3)) & 030707070707), \
- tmp = (tmp + (tmp >> 6)), \
- tmp = (tmp + (tmp >> 12) + (tmp >> 24)) & 077);
+ if (BITW_LEN == 32)
+ {
+ /* (C) Donald W. Gillies, 1992. All rights reserved. You may reuse
+ this bitcount() function anywhere you please as long as you retain
+ this Copyright Notice. */
+ register unsigned long tmp;
+ return (tmp = (n) - (((n) >> 1) & 033333333333) -
+ (((n) >> 2) & 011111111111),
+ tmp = ((tmp + (tmp >> 3)) & 030707070707),
+ tmp = (tmp + (tmp >> 6)),
+ tmp = (tmp + (tmp >> 12) + (tmp >> 24)) & 077);
+ /* End of Donald W. Gillies bitcount code */
+ }
+ else
+ {
+ /* Handle non-32 bit case the slow way */
+ int nbits = 0;
+ while (n)
+ {
+ if (n & 1)
+ nbits++;
+ n = n >> 1;
+ }
+ return nbits;
+ }