diff options
Diffstat (limited to 'deps/v8/src/utils/utils.h')
-rw-r--r-- | deps/v8/src/utils/utils.h | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/deps/v8/src/utils/utils.h b/deps/v8/src/utils/utils.h index 20d85aae10..27d3d5ef21 100644 --- a/deps/v8/src/utils/utils.h +++ b/deps/v8/src/utils/utils.h @@ -20,10 +20,13 @@ #include "src/base/platform/platform.h" #include "src/base/v8-fallthrough.h" #include "src/common/globals.h" -#include "src/third_party/siphash/halfsiphash.h" #include "src/utils/allocation.h" #include "src/utils/vector.h" +#if defined(V8_USE_SIPHASH) +#include "src/third_party/siphash/halfsiphash.h" +#endif + #if defined(V8_OS_AIX) #include <fenv.h> // NOLINT(build/c++11) #endif @@ -302,29 +305,36 @@ T SaturateSub(T a, T b) { // ---------------------------------------------------------------------------- // BitField is a help template for encoding and decode bitfield with // unsigned content. +// Instantiate them via 'using', which is cheaper than deriving a new class: +// using MyBitField = BitField<int, 4, 2, MyEnum>; +// The BitField class is final to enforce this style over derivation. template <class T, int shift, int size, class U = uint32_t> -class BitField { +class BitField final { public: STATIC_ASSERT(std::is_unsigned<U>::value); STATIC_ASSERT(shift < 8 * sizeof(U)); // Otherwise shifts by {shift} are UB. STATIC_ASSERT(size < 8 * sizeof(U)); // Otherwise shifts by {size} are UB. STATIC_ASSERT(shift + size <= 8 * sizeof(U)); + STATIC_ASSERT(size > 0); using FieldType = T; // 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 constexpr U kShift = shift; - static constexpr U kSize = size; + static constexpr int kShift = shift; + static constexpr int kSize = size; static constexpr U kMask = ((U{1} << kShift) << kSize) - (U{1} << kShift); - static constexpr U kNext = kShift + kSize; + static constexpr int kLastUsedBit = kShift + kSize - 1; static constexpr U kNumValues = U{1} << kSize; // Value for the field with all bits set. static constexpr T kMax = static_cast<T>(kNumValues - 1); + template <class T2, int size2> + using Next = BitField<T2, kShift + kSize, size2, U>; + // Tells whether the provided value fits into the bit field. static constexpr bool is_valid(T value) { return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0; @@ -892,7 +902,8 @@ class BailoutId { // Our version of printf(). V8_EXPORT_PRIVATE void PRINTF_FORMAT(1, 2) PrintF(const char* format, ...); -void PRINTF_FORMAT(2, 3) PrintF(FILE* out, const char* format, ...); +V8_EXPORT_PRIVATE void PRINTF_FORMAT(2, 3) + PrintF(FILE* out, const char* format, ...); // Prepends the current process ID to the output. void PRINTF_FORMAT(1, 2) PrintPID(const char* format, ...); |