28 #ifndef V8_COMPILER_INTRINSICS_H_
29 #define V8_COMPILER_INTRINSICS_H_
38 INLINE(
static int CountTrailingZeros(uint32_t value));
42 INLINE(
static int CountLeadingZeros(uint32_t value));
45 INLINE(
static int CountSetBits(uint32_t value));
49 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) {
50 return __builtin_ctz(value);
53 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) {
54 return __builtin_clz(value);
57 int CompilerIntrinsics::CountSetBits(uint32_t value) {
58 return __builtin_popcount(value);
61 #elif defined(_MSC_VER)
63 #pragma intrinsic(_BitScanForward)
64 #pragma intrinsic(_BitScanReverse)
66 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) {
68 _BitScanForward(&result, static_cast<long>(value));
69 return static_cast<int>(result);
72 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) {
74 _BitScanReverse(&result, static_cast<long>(value));
75 return 31 -
static_cast<int>(result);
78 int CompilerIntrinsics::CountSetBits(uint32_t value) {
80 value = ((value >> 1) & 0x55555555) + (value & 0x55555555);
81 value = ((value >> 2) & 0x33333333) + (value & 0x33333333);
82 value = ((value >> 4) & 0x0f0f0f0f) + (value & 0x0f0f0f0f);
83 value = ((value >> 8) & 0x00ff00ff) + (value & 0x00ff00ff);
84 value = ((value >> 16) & 0x0000ffff) + (value & 0x0000ffff);
89 #error Unsupported compiler
94 #endif // V8_COMPILER_INTRINSICS_H_
INLINE(static int CountTrailingZeros(uint32_t value))