diff options
Diffstat (limited to 'deps/v8/src/utils.h')
-rw-r--r-- | deps/v8/src/utils.h | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/deps/v8/src/utils.h b/deps/v8/src/utils.h index 26c522b89..68b1517de 100644 --- a/deps/v8/src/utils.h +++ b/deps/v8/src/utils.h @@ -47,13 +47,13 @@ namespace internal { // Returns true iff x is a power of 2 (or zero). Cannot be used with the // maximally negative value of the type T (the -1 overflows). template <typename T> -static inline bool IsPowerOf2(T x) { +inline bool IsPowerOf2(T x) { return IS_POWER_OF_TWO(x); } // X must be a power of 2. Returns the number of trailing zeros. -static inline int WhichPowerOf2(uint32_t x) { +inline int WhichPowerOf2(uint32_t x) { ASSERT(IsPowerOf2(x)); ASSERT(x != 0); int bits = 0; @@ -88,7 +88,7 @@ static inline int WhichPowerOf2(uint32_t x) { // The C++ standard leaves the semantics of '>>' undefined for // negative signed operands. Most implementations do the right thing, // though. -static inline int ArithmeticShiftRight(int x, int s) { +inline int ArithmeticShiftRight(int x, int s) { return x >> s; } @@ -97,7 +97,7 @@ static inline int ArithmeticShiftRight(int x, int s) { // This allows conversion of Addresses and integral types into // 0-relative int offsets. template <typename T> -static inline intptr_t OffsetFrom(T x) { +inline intptr_t OffsetFrom(T x) { return x - static_cast<T>(0); } @@ -106,14 +106,14 @@ static inline intptr_t OffsetFrom(T x) { // This allows conversion of 0-relative int offsets into Addresses and // integral types. template <typename T> -static inline T AddressFrom(intptr_t x) { +inline T AddressFrom(intptr_t x) { return static_cast<T>(static_cast<T>(0) + x); } // Return the largest multiple of m which is <= x. template <typename T> -static inline T RoundDown(T x, int m) { +inline T RoundDown(T x, intptr_t m) { ASSERT(IsPowerOf2(m)); return AddressFrom<T>(OffsetFrom(x) & -m); } @@ -121,13 +121,13 @@ static inline T RoundDown(T x, int m) { // Return the smallest multiple of m which is >= x. template <typename T> -static inline T RoundUp(T x, int m) { - return RoundDown(x + m - 1, m); +inline T RoundUp(T x, intptr_t m) { + return RoundDown<T>(static_cast<T>(x + m - 1), m); } template <typename T> -static int Compare(const T& a, const T& b) { +int Compare(const T& a, const T& b) { if (a == b) return 0; else if (a < b) @@ -138,16 +138,26 @@ static int Compare(const T& a, const T& b) { template <typename T> -static int PointerValueCompare(const T* a, const T* b) { +int PointerValueCompare(const T* a, const T* b) { return Compare<T>(*a, *b); } +// Compare function to compare the object pointer value of two +// handlified objects. The handles are passed as pointers to the +// handles. +template<typename T> class Handle; // Forward declaration. +template <typename T> +int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { + return Compare<T*>(*(*a), *(*b)); +} + + // Returns the smallest power of two which is >= x. If you pass in a // number that is already a power of two, it is returned as is. // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., // figure 3-3, page 48, where the function is called clp2. -static inline uint32_t RoundUpToPowerOf2(uint32_t x) { +inline uint32_t RoundUpToPowerOf2(uint32_t x) { ASSERT(x <= 0x80000000u); x = x - 1; x = x | (x >> 1); @@ -159,18 +169,23 @@ static inline uint32_t RoundUpToPowerOf2(uint32_t x) { } +inline uint32_t RoundDownToPowerOf2(uint32_t x) { + uint32_t rounded_up = RoundUpToPowerOf2(x); + if (rounded_up > x) return rounded_up >> 1; + return rounded_up; +} + -template <typename T> -static inline bool IsAligned(T value, T alignment) { - ASSERT(IsPowerOf2(alignment)); +template <typename T, typename U> +inline bool IsAligned(T value, U alignment) { return (value & (alignment - 1)) == 0; } // Returns true if (addr + offset) is aligned. -static inline bool IsAddressAligned(Address addr, - intptr_t alignment, - int offset) { +inline bool IsAddressAligned(Address addr, + intptr_t alignment, + int offset = 0) { intptr_t offs = OffsetFrom(addr + offset); return IsAligned(offs, alignment); } @@ -178,14 +193,14 @@ static inline bool IsAddressAligned(Address addr, // Returns the maximum of the two parameters. template <typename T> -static T Max(T a, T b) { +T Max(T a, T b) { return a < b ? b : a; } // Returns the minimum of the two parameters. template <typename T> -static T Min(T a, T b) { +T Min(T a, T b) { return a < b ? a : b; } @@ -239,7 +254,7 @@ class BitField { // Thomas Wang, Integer Hash Functions. // http://www.concentric.net/~Ttwang/tech/inthash.htm -static inline uint32_t ComputeIntegerHash(uint32_t key) { +inline uint32_t ComputeIntegerHash(uint32_t key) { uint32_t hash = key; hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; hash = hash ^ (hash >> 12); @@ -251,7 +266,19 @@ static inline uint32_t ComputeIntegerHash(uint32_t key) { } -static inline uint32_t ComputePointerHash(void* ptr) { +inline uint32_t ComputeLongHash(uint64_t key) { + uint64_t hash = key; + hash = ~hash + (hash << 18); // hash = (hash << 18) - hash - 1; + hash = hash ^ (hash >> 31); + hash = hash * 21; // hash = (hash + (hash << 2)) + (hash << 4); + hash = hash ^ (hash >> 11); + hash = hash + (hash << 6); + hash = hash ^ (hash >> 22); + return (uint32_t) hash; +} + + +inline uint32_t ComputePointerHash(void* ptr) { return ComputeIntegerHash( static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr))); } @@ -707,7 +734,7 @@ class SequenceCollector : public Collector<T, growth_factor, max_growth> { // Compare ASCII/16bit chars to ASCII/16bit chars. template <typename lchar, typename rchar> -static inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { +inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { const lchar* limit = lhs + chars; #ifdef V8_HOST_CAN_READ_UNALIGNED if (sizeof(*lhs) == sizeof(*rhs)) { @@ -734,7 +761,7 @@ static inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { // Calculate 10^exponent. -static inline int TenToThe(int exponent) { +inline int TenToThe(int exponent) { ASSERT(exponent <= 9); ASSERT(exponent >= 1); int answer = 10; |