diff options
Diffstat (limited to 'deps/v8/src/utils.h')
-rw-r--r-- | deps/v8/src/utils.h | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/deps/v8/src/utils.h b/deps/v8/src/utils.h index b2c2ff1098..93cded18bc 100644 --- a/deps/v8/src/utils.h +++ b/deps/v8/src/utils.h @@ -242,42 +242,52 @@ inline int StrLength(const char* string) { // ---------------------------------------------------------------------------- // BitField is a help template for encoding and decode bitfield with // unsigned content. -template<class T, int shift, int size> -class BitField { + +template<class T, int shift, int size, class U> +class BitFieldBase { public: - // A uint32_t mask of bit field. To use all bits of a uint32 in a - // bitfield without compiler warnings we have to compute 2^32 without - // using a shift count of 32. - static const uint32_t kMask = ((1U << shift) << size) - (1U << shift); - static const uint32_t kShift = shift; - static const uint32_t kSize = size; + // A type U mask of bit field. To use all bits of a type U of x bits + // in a bitfield without compiler warnings we have to compute 2^x + // without using a shift count of x in the computation. + static const U kOne = static_cast<U>(1U); + static const U kMask = ((kOne << shift) << size) - (kOne << shift); + static const U kShift = shift; + static const U kSize = size; // Value for the field with all bits set. static const T kMax = static_cast<T>((1U << size) - 1); // Tells whether the provided value fits into the bit field. static bool is_valid(T value) { - return (static_cast<uint32_t>(value) & ~static_cast<uint32_t>(kMax)) == 0; + return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0; } - // Returns a uint32_t with the bit field value encoded. - static uint32_t encode(T value) { + // Returns a type U with the bit field value encoded. + static U encode(T value) { ASSERT(is_valid(value)); - return static_cast<uint32_t>(value) << shift; + return static_cast<U>(value) << shift; } - // Returns a uint32_t with the bit field value updated. - static uint32_t update(uint32_t previous, T value) { + // Returns a type U with the bit field value updated. + static U update(U previous, T value) { return (previous & ~kMask) | encode(value); } // Extracts the bit field from the value. - static T decode(uint32_t value) { + static T decode(U value) { return static_cast<T>((value & kMask) >> shift); } }; +template<class T, int shift, int size> +class BitField : public BitFieldBase<T, shift, size, uint32_t> { }; + + +template<class T, int shift, int size> +class BitField64 : public BitFieldBase<T, shift, size, uint64_t> { }; + + // ---------------------------------------------------------------------------- // Hash function. @@ -1030,6 +1040,7 @@ class EnumSet { void Intersect(const EnumSet& set) { bits_ &= set.bits_; } T ToIntegral() const { return bits_; } bool operator==(const EnumSet& set) { return bits_ == set.bits_; } + bool operator!=(const EnumSet& set) { return bits_ != set.bits_; } EnumSet<E, T> operator|(const EnumSet& set) const { return EnumSet<E, T>(bits_ | set.bits_); } |