Adapt hash tests to big-endian systems.

The hash code, which has MurmurHash3 at its core, generates different
output depending on system endianness, so adapt the expected output on
big-endian systems.  MurmurHash3 code also makes the assumption that
unaligned access is okay (not true on all systems), but jemalloc only
hashes data structures that have sufficient alignment to dodge this
limitation.
This commit is contained in:
Jason Evans 2014-03-30 16:27:08 -07:00
parent ada8447cf6
commit df3f27024f
4 changed files with 15 additions and 1 deletions

View File

@ -150,6 +150,11 @@ if test "x$EXTRA_CFLAGS" != "x" ; then
fi fi
AC_PROG_CPP AC_PROG_CPP
AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
if test "x${ac_cv_big_endian}" = "x1" ; then
AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
fi
AC_CHECK_SIZEOF([void *]) AC_CHECK_SIZEOF([void *])
if test "x${ac_cv_sizeof_void_p}" = "x8" ; then if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
LG_SIZEOF_PTR=3 LG_SIZEOF_PTR=3

View File

@ -320,7 +320,7 @@ hash_x64_128(const void *key, const int len, const uint32_t seed,
JEMALLOC_INLINE void JEMALLOC_INLINE void
hash(const void *key, size_t len, const uint32_t seed, size_t r_hash[2]) hash(const void *key, size_t len, const uint32_t seed, size_t r_hash[2])
{ {
#if (LG_SIZEOF_PTR == 3) #if (LG_SIZEOF_PTR == 3 && !defined(JEMALLOC_BIG_ENDIAN))
hash_x64_128(key, len, seed, (uint64_t *)r_hash); hash_x64_128(key, len, seed, (uint64_t *)r_hash);
#else #else
uint64_t hashes[2]; uint64_t hashes[2];

View File

@ -190,6 +190,9 @@
/* C99 restrict keyword supported. */ /* C99 restrict keyword supported. */
#undef JEMALLOC_HAS_RESTRICT #undef JEMALLOC_HAS_RESTRICT
/* For use by hash code. */
#undef JEMALLOC_BIG_ENDIAN
/* sizeof(int) == 2^LG_SIZEOF_INT. */ /* sizeof(int) == 2^LG_SIZEOF_INT. */
#undef LG_SIZEOF_INT #undef LG_SIZEOF_INT

View File

@ -122,9 +122,15 @@ hash_variant_verify(hash_variant_t variant)
(final[3] << 24); (final[3] << 24);
switch (variant) { switch (variant) {
#ifdef JEMALLOC_BIG_ENDIAN
case hash_variant_x86_32: expected = 0x6213303eU; break;
case hash_variant_x86_128: expected = 0x266820caU; break;
case hash_variant_x64_128: expected = 0xcc622b6fU; break;
#else
case hash_variant_x86_32: expected = 0xb0f57ee3U; break; case hash_variant_x86_32: expected = 0xb0f57ee3U; break;
case hash_variant_x86_128: expected = 0xb3ece62aU; break; case hash_variant_x86_128: expected = 0xb3ece62aU; break;
case hash_variant_x64_128: expected = 0x6384ba69U; break; case hash_variant_x64_128: expected = 0x6384ba69U; break;
#endif
default: not_reached(); default: not_reached();
} }