# HG changeset patch # User Ben Pfaff # Date 1185244509 0 # Node ID 2b6b38e4a82ef79b3dd729d7e7aed345a3a89012 # Parent af87f682cfec32ec6c88cc3c08975b3acfce6b14 (popcount32): Reduce size of constants, to allow better code generation, and add U to large constants to avoid warnings, in non-GCC case. Suggested by Bruno Haible. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-07-23 Ben Pfaff + + * lib/popcount.h (popcount32): Reduce size of constants, to allow + better code generation, and add U to large constants to avoid + warnings, in non-GCC case. + Suggested by Bruno Haible. + 2007-07-23 Ben Pfaff * lib/popcount.h: Use verify_true instead of if...abort. diff --git a/lib/popcount.h b/lib/popcount.h --- a/lib/popcount.h +++ b/lib/popcount.h @@ -41,11 +41,11 @@ static inline int popcount32 (unsigned int x) { - x = ((x & 0xaaaaaaaa) >> 1) + (x & 0x55555555); - x = ((x & 0xcccccccc) >> 2) + (x & 0x33333333); - x = ((x & 0xf0f0f0f0) >> 4) + (x & 0x0f0f0f0f); - x = ((x & 0xff00ff00) >> 8) + (x & 0x00ff00ff); - return (x >> 16) + (x & 0xff); + x = ((x & 0xaaaaaaaaU) >> 1) + (x & 0x55555555U); + x = ((x & 0xccccccccU) >> 2) + (x & 0x33333333U); + x = (x >> 16) + (x & 0xffff); + x = ((x & 0xf0f0) >> 4) + (x & 0x0f0f); + return (x >> 8) + (x & 0x00ff); } #endif