5 #ifndef V8_BASE_BITS_H_
6 #define V8_BASE_BITS_H_
23 #if V8_HAS_BUILTIN_POPCOUNT
24 return __builtin_popcount(value);
26 value = ((value >> 1) & 0x55555555) + (value & 0x55555555);
27 value = ((value >> 2) & 0x33333333) + (value & 0x33333333);
28 value = ((value >> 4) & 0x0f0f0f0f) + (value & 0x0f0f0f0f);
29 value = ((value >> 8) & 0x00ff00ff) + (value & 0x00ff00ff);
30 value = ((value >> 16) & 0x0000ffff) + (value & 0x0000ffff);
39 #if V8_HAS_BUILTIN_CLZ
40 return value ? __builtin_clz(value) : 32;
43 if (!_BitScanReverse(&result, value))
return 32;
44 return static_cast<uint32_t>(31 - result);
46 value = value | (value >> 1);
47 value = value | (value >> 2);
48 value = value | (value >> 4);
49 value = value | (value >> 8);
50 value = value | (value >> 16);
60 #if V8_HAS_BUILTIN_CTZ
61 return value ? __builtin_ctz(value) : 32;
64 if (!_BitScanForward(&result, value))
return 32;
65 return static_cast<uint32_t>(result);
67 if (value == 0)
return 32;
69 for (value ^= value - 1; value >>= 1; ++count)
78 return value && !(value & (value - 1));
84 return value && !(value & (value - 1));
100 if (value > 0x80000000u)
return 0x80000000u;
102 if (result > value) result >>= 1;
108 if (
shift == 0)
return value;
109 return (value >>
shift) | (value << (32 -
shift));
114 if (
shift == 0)
return value;
115 return (value >>
shift) | (value << (64 -
shift));
123 #if V8_HAS_BUILTIN_SADD_OVERFLOW
124 return __builtin_sadd_overflow(lhs, rhs, val);
127 *val = bit_cast<int32_t>(res);
128 return ((res ^ lhs) & (res ^ rhs) & (1U << 31)) != 0;
137 #if V8_HAS_BUILTIN_SSUB_OVERFLOW
138 return __builtin_ssub_overflow(lhs, rhs, val);
141 *val = bit_cast<int32_t>(res);
142 return ((res ^ lhs) & (res ^ ~rhs) & (1U << 31)) != 0;
enable harmony numeric enable harmony object literal extensions Optimize object Array shift
uint32_t CountTrailingZeros32(uint32_t value)
uint32_t RoundUpToPowerOfTwo32(uint32_t value)
uint32_t CountPopulation32(uint32_t value)
uint32_t RoundDownToPowerOfTwo32(uint32_t value)
uint32_t CountLeadingZeros32(uint32_t value)
uint32_t RotateRight32(uint32_t value, uint32_t shift)
bool IsPowerOfTwo64(uint64_t value)
bool IsPowerOfTwo32(uint32_t value)
bool SignedAddOverflow32(int32_t lhs, int32_t rhs, int32_t *val)
uint64_t RotateRight64(uint64_t value, uint64_t shift)
bool SignedSubOverflow32(int32_t lhs, int32_t rhs, int32_t *val)
Debugger support for the V8 JavaScript engine.