Index: src/compiler-intrinsics.h |
=================================================================== |
--- src/compiler-intrinsics.h (revision 10969) |
+++ src/compiler-intrinsics.h (working copy) |
@@ -40,6 +40,9 @@ |
// Returns number of zero bits following most significant 1 bit. |
// Undefined for zero value. |
INLINE(static int CountLeadingZeros(uint32_t value)); |
+ |
+ // Returns the number of bits set. |
+ INLINE(static int CountSetBits(uint32_t value)); |
}; |
#ifdef __GNUC__ |
@@ -51,6 +54,10 @@ |
return __builtin_clz(value); |
} |
+int CompilerIntrinsics::CountSetBits(uint32_t value) { |
+ return __builtin_popcount(value); |
+} |
+ |
#elif defined(_MSC_VER) |
#pragma intrinsic(_BitScanForward) |
@@ -68,6 +75,10 @@ |
return 31 - static_cast<int>(result); |
} |
+int CompilerIntrinsics::CountSetBits(uint32_t value) { |
+ return __popcnt(value); |
+} |
+ |
#else |
#error Unsupported compiler |
#endif |