diff options
Diffstat (limited to 'deps/v8/src/base/bits.h')
-rw-r--r-- | deps/v8/src/base/bits.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/deps/v8/src/base/bits.h b/deps/v8/src/base/bits.h index b1864940b8..362940fcbe 100644 --- a/deps/v8/src/base/bits.h +++ b/deps/v8/src/base/bits.h @@ -158,23 +158,25 @@ inline unsigned CountTrailingZeros(uint64_t value) { } // Returns true iff |value| is a power of 2. -inline bool IsPowerOfTwo32(uint32_t value) { +constexpr inline bool IsPowerOfTwo32(uint32_t value) { return value && !(value & (value - 1)); } // Returns true iff |value| is a power of 2. -inline bool IsPowerOfTwo64(uint64_t value) { +constexpr inline bool IsPowerOfTwo64(uint64_t value) { return value && !(value & (value - 1)); } - // RoundUpToPowerOfTwo32(value) returns the smallest power of two which is // greater than or equal to |value|. If you pass in a |value| that is already a // power of two, it is returned as is. |value| must be less than or equal to -// 0x80000000u. Implementation is from "Hacker's Delight" by Henry S. Warren, -// Jr., figure 3-3, page 48, where the function is called clp2. +// 0x80000000u. Uses computation based on leading zeros if we have compiler +// support for that. Falls back to the implementation from "Hacker's Delight" by +// Henry S. Warren, Jr., figure 3-3, page 48, where the function is called clp2. V8_BASE_EXPORT uint32_t RoundUpToPowerOfTwo32(uint32_t value); +// Same for 64 bit integers. |value| must be <= 2^63 +V8_BASE_EXPORT uint64_t RoundUpToPowerOfTwo64(uint64_t value); // RoundDownToPowerOfTwo32(value) returns the greatest power of two which is // less than or equal to |value|. If you pass in a |value| that is already a |