(popcount32): Reduce size of constants, to allow better code
authorBen Pfaff <blp@gnu.org>
Tue, 24 Jul 2007 02:35:09 +0000 (02:35 +0000)
committerBen Pfaff <blp@gnu.org>
Tue, 24 Jul 2007 02:35:09 +0000 (02:35 +0000)
generation, and add U to large constants to avoid warnings, in non-GCC
case.
Suggested by Bruno Haible.

ChangeLog
lib/popcount.h

index c8c539dc4765b799a8ffeea76ccd6e9f63864ab8..6c0445071a78540150a89f8e57274566517336af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-07-23  Ben Pfaff  <blp@gnu.org>
+
+       * 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  <blp@gnu.org>
 
        * lib/popcount.h: Use verify_true instead of if...abort.
index 6c19de2d626b2560d59e6fc6b41a2d7f3ba07518..0ea6ed837421b6e51e2105cef5515c3c46194a20 100644 (file)
 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