From 7b4adf5c0f67453aeb9f16c5f1661e9984978ae4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 20 Jan 2014 08:58:26 +0100 Subject: [PATCH] Bug 937952 - Replace JS_ROTATE_LEFT32 with mozilla::RotateLeft; r=Waldo --- js/jsd/jshash.cpp | 3 ++- js/public/Utility.h | 20 -------------------- js/src/jit/RegisterAllocator.h | 5 +++-- js/src/jsscript.cpp | 12 +++++++----- js/src/vm/Shape.cpp | 17 +++++++++-------- js/src/vm/Shape.h | 11 ++++++----- js/xpconnect/src/XPCMaps.cpp | 5 ++++- 7 files changed, 31 insertions(+), 42 deletions(-) diff --git a/js/jsd/jshash.cpp b/js/jsd/jshash.cpp index 6949dbf72d8a..abfcfff2a902 100644 --- a/js/jsd/jshash.cpp +++ b/js/jsd/jshash.cpp @@ -22,6 +22,7 @@ using namespace js; using mozilla::CeilingLog2Size; +using mozilla::RotateLeft; /* Compute the number of buckets in ht */ #define NBUCKETS(ht) JS_BIT(JS_HASH_BITS - (ht)->shift) @@ -441,7 +442,7 @@ JS_HashString(const void *key) h = 0; for (s = (const unsigned char *)key; *s; s++) - h = JS_ROTATE_LEFT32(h, 4) ^ *s; + h = RotateLeft(h, 4) ^ *s; return h; } diff --git a/js/public/Utility.h b/js/public/Utility.h index 5607e1dffb06..f7f6e3f3b025 100644 --- a/js/public/Utility.h +++ b/js/public/Utility.h @@ -168,26 +168,6 @@ static inline void js_free(void* p) } #endif/* JS_USE_CUSTOM_ALLOCATOR */ -/* - * JS_ROTATE_LEFT32 - * - * There is no rotate operation in the C Language so the construct (a << 4) | - * (a >> 28) is used instead. Most compilers convert this to a rotate - * instruction but some versions of MSVC don't without a little help. To get - * MSVC to generate a rotate instruction, we have to use the _rotl intrinsic - * and use a pragma to make _rotl inline. - * - * MSVC in VS2005 will do an inline rotate instruction on the above construct. - */ -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ - defined(_M_X64)) -#include -#pragma intrinsic(_rotl) -#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits) -#else -#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) -#endif - #include /* diff --git a/js/src/jit/RegisterAllocator.h b/js/src/jit/RegisterAllocator.h index e8cbe6056ad5..879c69ff317b 100644 --- a/js/src/jit/RegisterAllocator.h +++ b/js/src/jit/RegisterAllocator.h @@ -8,6 +8,7 @@ #define jit_RegisterAllocator_h #include "mozilla/Attributes.h" +#include "mozilla/MathAlgorithms.h" #include "jit/LIR.h" #include "jit/MIRGenerator.h" @@ -97,8 +98,8 @@ struct AllocationIntegrityState typedef IntegrityItem Lookup; static HashNumber hash(const IntegrityItem &item) { HashNumber hash = item.alloc.hash(); - hash = JS_ROTATE_LEFT32(hash, 4) ^ item.vreg; - hash = JS_ROTATE_LEFT32(hash, 4) ^ HashNumber(item.block->mir()->id()); + hash = mozilla::RotateLeft(hash, 4) ^ item.vreg; + hash = mozilla::RotateLeft(hash, 4) ^ HashNumber(item.block->mir()->id()); return hash; } static bool match(const IntegrityItem &one, const IntegrityItem &two) { diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index a4477a627a73..0ca75cb83b36 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -10,6 +10,7 @@ #include "jsscriptinlines.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/MemoryReporting.h" #include "mozilla/PodOperations.h" @@ -51,6 +52,7 @@ using namespace js::frontend; using mozilla::PodCopy; using mozilla::PodZero; +using mozilla::RotateLeft; typedef Rooted RootedGlobalObject; @@ -3226,13 +3228,13 @@ LazyScriptHash(uint32_t lineno, uint32_t column, uint32_t begin, uint32_t end, HashNumber hashes[3]) { HashNumber hash = lineno; - hash = JS_ROTATE_LEFT32(hash, 4) ^ column; - hash = JS_ROTATE_LEFT32(hash, 4) ^ begin; - hash = JS_ROTATE_LEFT32(hash, 4) ^ end; + hash = RotateLeft(hash, 4) ^ column; + hash = RotateLeft(hash, 4) ^ begin; + hash = RotateLeft(hash, 4) ^ end; hashes[0] = hash; - hashes[1] = JS_ROTATE_LEFT32(hashes[0], 4) ^ begin; - hashes[2] = JS_ROTATE_LEFT32(hashes[1], 4) ^ end; + hashes[1] = RotateLeft(hashes[0], 4) ^ begin; + hashes[2] = RotateLeft(hashes[1], 4) ^ end; } void diff --git a/js/src/vm/Shape.cpp b/js/src/vm/Shape.cpp index 6a688e814bac..8cb327de7993 100644 --- a/js/src/vm/Shape.cpp +++ b/js/src/vm/Shape.cpp @@ -28,9 +28,10 @@ using namespace js; using namespace js::gc; +using mozilla::CeilingLog2Size; using mozilla::DebugOnly; using mozilla::PodZero; -using mozilla::CeilingLog2Size; +using mozilla::RotateLeft; bool ShapeTable::init(ThreadSafeContext *cx, Shape *lastProp) @@ -1432,11 +1433,11 @@ Shape::setObjectFlag(ExclusiveContext *cx, BaseShape::Flag flag, TaggedProto pro StackBaseShape::hash(const StackBaseShape *base) { HashNumber hash = base->flags; - hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(base->clasp) >> 3); - hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(base->parent) >> 3); - hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(base->metadata) >> 3); - hash = JS_ROTATE_LEFT32(hash, 4) ^ uintptr_t(base->rawGetter); - hash = JS_ROTATE_LEFT32(hash, 4) ^ uintptr_t(base->rawSetter); + hash = RotateLeft(hash, 4) ^ (uintptr_t(base->clasp) >> 3); + hash = RotateLeft(hash, 4) ^ (uintptr_t(base->parent) >> 3); + hash = RotateLeft(hash, 4) ^ (uintptr_t(base->metadata) >> 3); + hash = RotateLeft(hash, 4) ^ uintptr_t(base->rawGetter); + hash = RotateLeft(hash, 4) ^ uintptr_t(base->rawSetter); return hash; } @@ -1575,9 +1576,9 @@ InitialShapeEntry::getLookup() const InitialShapeEntry::hash(const Lookup &lookup) { HashNumber hash = uintptr_t(lookup.clasp) >> 3; - hash = JS_ROTATE_LEFT32(hash, 4) ^ + hash = RotateLeft(hash, 4) ^ (uintptr_t(lookup.hashProto.toWord()) >> 3); - hash = JS_ROTATE_LEFT32(hash, 4) ^ + hash = RotateLeft(hash, 4) ^ (uintptr_t(lookup.hashParent) >> 3) ^ (uintptr_t(lookup.hashMetadata) >> 3); return hash + lookup.nfixed; diff --git a/js/src/vm/Shape.h b/js/src/vm/Shape.h index a5423689f60e..e8c27bbf1de8 100644 --- a/js/src/vm/Shape.h +++ b/js/src/vm/Shape.h @@ -9,6 +9,7 @@ #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/Maybe.h" #include "mozilla/MemoryReporting.h" #include "mozilla/TemplateLib.h" @@ -1549,11 +1550,11 @@ struct StackShape HashNumber hash = uintptr_t(base); /* Accumulate from least to most random so the low bits are most random. */ - hash = JS_ROTATE_LEFT32(hash, 4) ^ (flags & Shape::PUBLIC_FLAGS); - hash = JS_ROTATE_LEFT32(hash, 4) ^ attrs; - hash = JS_ROTATE_LEFT32(hash, 4) ^ shortid; - hash = JS_ROTATE_LEFT32(hash, 4) ^ slot_; - hash = JS_ROTATE_LEFT32(hash, 4) ^ JSID_BITS(propid); + hash = mozilla::RotateLeft(hash, 4) ^ (flags & Shape::PUBLIC_FLAGS); + hash = mozilla::RotateLeft(hash, 4) ^ attrs; + hash = mozilla::RotateLeft(hash, 4) ^ shortid; + hash = mozilla::RotateLeft(hash, 4) ^ slot_; + hash = mozilla::RotateLeft(hash, 4) ^ JSID_BITS(propid); return hash; } diff --git a/js/xpconnect/src/XPCMaps.cpp b/js/xpconnect/src/XPCMaps.cpp index ebde7ef01524..0b858c516330 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -6,11 +6,14 @@ /* Private maps (hashtables). */ +#include "mozilla/MathAlgorithms.h" #include "mozilla/MemoryReporting.h" #include "xpcprivate.h" #include "js/HashTable.h" +using namespace mozilla; + /***************************************************************************/ // static shared... @@ -518,7 +521,7 @@ XPCNativeScriptableSharedMap::Entry::Hash(PLDHashTable *table, const void *key) h = (PLDHashNumber) obj->GetFlags(); for (s = (const unsigned char*) obj->GetJSClass()->name; *s != '\0'; s++) - h = JS_ROTATE_LEFT32(h, 4) ^ *s; + h = RotateLeft(h, 4) ^ *s; return h; }