зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1443342 - Remove HashFunctions.h's RotateBitsLeft32 and use the general RotateLeft function instead. r=froydnj
--HG-- extra : rebase_source : 88ad42c5757d9f1f0df5590c647a840061523318
This commit is contained in:
Родитель
8622941e2a
Коммит
75f86d4202
|
@ -56,7 +56,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
|
@ -64,13 +63,6 @@ namespace mozilla {
|
|||
*/
|
||||
static const uint32_t kGoldenRatioU32 = 0x9E3779B9U;
|
||||
|
||||
inline uint32_t
|
||||
RotateBitsLeft32(uint32_t aValue, uint8_t aBits)
|
||||
{
|
||||
MOZ_ASSERT(aBits < 32);
|
||||
return (aValue << aBits) | (aValue >> (32 - aBits));
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline uint32_t
|
||||
|
@ -104,21 +96,21 @@ AddU32ToHash(uint32_t aHash, uint32_t aValue)
|
|||
* evaluates to |aValue|.
|
||||
*
|
||||
* (Number-theoretic aside: Because any odd number |m| is relatively prime to
|
||||
* our modulus (2^32), the list
|
||||
* our modulus (2**32), the list
|
||||
*
|
||||
* [x * m (mod 2^32) for 0 <= x < 2^32]
|
||||
* [x * m (mod 2**32) for 0 <= x < 2**32]
|
||||
*
|
||||
* has no duplicate elements. This means that multiplying by |m| does not
|
||||
* cause us to skip any possible hash values.
|
||||
*
|
||||
* It's also nice if |m| has large-ish order mod 2^32 -- that is, if the
|
||||
* smallest k such that m^k == 1 (mod 2^32) is large -- so we can safely
|
||||
* It's also nice if |m| has large-ish order mod 2**32 -- that is, if the
|
||||
* smallest k such that m**k == 1 (mod 2**32) is large -- so we can safely
|
||||
* multiply our hash value by |m| a few times without negating the
|
||||
* multiplicative effect. Our golden ratio constant has order 2^29, which is
|
||||
* multiplicative effect. Our golden ratio constant has order 2**29, which is
|
||||
* more than enough for our purposes.)
|
||||
*/
|
||||
return mozilla::WrappingMultiply(kGoldenRatioU32,
|
||||
(RotateBitsLeft32(aHash, 5) ^ aValue));
|
||||
RotateLeft(aHash, 5) ^ aValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -383,6 +375,5 @@ private:
|
|||
};
|
||||
|
||||
} /* namespace mozilla */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* mozilla_HashFunctions_h */
|
||||
|
|
|
@ -480,16 +480,19 @@ RoundUpPow2(size_t aValue)
|
|||
* Rotates the bits of the given value left by the amount of the shift width.
|
||||
*/
|
||||
template<typename T>
|
||||
MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW
|
||||
inline T
|
||||
RotateLeft(const T aValue, uint_fast8_t aShift)
|
||||
{
|
||||
static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
|
||||
|
||||
MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!");
|
||||
MOZ_ASSERT(aShift > 0,
|
||||
"Rotation by value length is undefined behavior, but compilers "
|
||||
"do not currently fold a test into the rotate instruction. "
|
||||
"Please remove this restriction when compilers optimize the "
|
||||
"zero case (http://blog.regehr.org/archives/1063).");
|
||||
static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
|
||||
|
||||
return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift));
|
||||
}
|
||||
|
||||
|
@ -497,16 +500,19 @@ RotateLeft(const T aValue, uint_fast8_t aShift)
|
|||
* Rotates the bits of the given value right by the amount of the shift width.
|
||||
*/
|
||||
template<typename T>
|
||||
MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW
|
||||
inline T
|
||||
RotateRight(const T aValue, uint_fast8_t aShift)
|
||||
{
|
||||
static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
|
||||
|
||||
MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!");
|
||||
MOZ_ASSERT(aShift > 0,
|
||||
"Rotation by value length is undefined behavior, but compilers "
|
||||
"do not currently fold a test into the rotate instruction. "
|
||||
"Please remove this restriction when compilers optimize the "
|
||||
"zero case (http://blog.regehr.org/archives/1063).");
|
||||
static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
|
||||
|
||||
return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift));
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче