|
|
|
@ -78,59 +78,30 @@ void hashMurmurx86 ( const void * key, const int len, const uint seed, void * ou |
|
|
|
|
* ROTL32(x,r) Rotate x left by r bits |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/* Convention is to define __BYTE_ORDER == to one of these values */ |
|
|
|
|
#if !defined(__BIG_ENDIAN) |
|
|
|
|
#define __BIG_ENDIAN 4321 |
|
|
|
|
#endif |
|
|
|
|
#if !defined(__LITTLE_ENDIAN) |
|
|
|
|
#define __LITTLE_ENDIAN 1234 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* I386 */ |
|
|
|
|
#if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386) |
|
|
|
|
#define __BYTE_ORDER __LITTLE_ENDIAN |
|
|
|
|
#define UNALIGNED_SAFE |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* gcc 'may' define __LITTLE_ENDIAN__ or __BIG_ENDIAN__ to 1 (Note the trailing __),
|
|
|
|
|
* or even _LITTLE_ENDIAN or _BIG_ENDIAN (Note the single _ prefix) */ |
|
|
|
|
#if !defined(__BYTE_ORDER) |
|
|
|
|
#if defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__==1 || defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN==1 |
|
|
|
|
#define __BYTE_ORDER __LITTLE_ENDIAN |
|
|
|
|
#elif defined(__BIG_ENDIAN__) && __BIG_ENDIAN__==1 || defined(_BIG_ENDIAN) && _BIG_ENDIAN==1 |
|
|
|
|
#define __BYTE_ORDER __BIG_ENDIAN |
|
|
|
|
#endif |
|
|
|
|
#if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386)) |
|
|
|
|
# define UNALIGNED_SAFE 1 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* gcc (usually) defines xEL/EB macros for ARM and MIPS endianess */ |
|
|
|
|
#if !defined(__BYTE_ORDER) |
|
|
|
|
#if defined(__ARMEL__) || defined(__MIPSEL__) |
|
|
|
|
#define __BYTE_ORDER __LITTLE_ENDIAN |
|
|
|
|
#endif |
|
|
|
|
#if defined(__ARMEB__) || defined(__MIPSEB__) |
|
|
|
|
#define __BYTE_ORDER __BIG_ENDIAN |
|
|
|
|
#endif |
|
|
|
|
#ifndef UNALIGNED_SAFE |
|
|
|
|
# define UNALIGNED_SAFE 1 |
|
|
|
|
#elif defined(UNALIGNED_SAFE) && !UNALIGNED_SAFE == 0 |
|
|
|
|
# undef UNALIGNED_SAFE |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* Now find best way we can to READ_UINT32 */ |
|
|
|
|
#if __BYTE_ORDER==__LITTLE_ENDIAN |
|
|
|
|
/* CPU endian matches murmurhash algorithm, so read 32-bit word directly */ |
|
|
|
|
#define READ_UINT32(ptr) (*((uint32_t*)(ptr))) |
|
|
|
|
#elif __BYTE_ORDER==__BIG_ENDIAN |
|
|
|
|
/* TODO: Add additional cases below where a compiler provided bswap32 is available */ |
|
|
|
|
#if defined(__GNUC__) && (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3)) |
|
|
|
|
#define READ_UINT32(ptr) (__builtin_bswap32(*((uint32_t*)(ptr)))) |
|
|
|
|
#else |
|
|
|
|
/* Without a known fast bswap32 we're just as well off doing this */ |
|
|
|
|
#define READ_UINT32(ptr) (ptr[0]|ptr[1]<<8|ptr[2]<<16|ptr[3]<<24) |
|
|
|
|
#define UNALIGNED_SAFE |
|
|
|
|
#if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386)) \ |
|
|
|
|
|| (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
|
|
|
|
# define READ_UINT32(ptr) (*((uint32_t*)(ptr))) |
|
|
|
|
#elif (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) |
|
|
|
|
&& defined(__GNUC__) && (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3)) |
|
|
|
|
# define READ_UINT32(ptr) (__builtin_bswap32(*((uint32_t*)(ptr)))) |
|
|
|
|
#endif |
|
|
|
|
#else |
|
|
|
|
/* Unknown endianess so last resort is to read individual bytes */ |
|
|
|
|
#define READ_UINT32(ptr) (ptr[0]|ptr[1]<<8|ptr[2]<<16|ptr[3]<<24) |
|
|
|
|
|
|
|
|
|
/* Since we're not doing word-reads we can skip the messing about with realignment */ |
|
|
|
|
#define UNALIGNED_SAFE |
|
|
|
|
#ifndef READ_UINT32 |
|
|
|
|
/* Unknown endianess so last resort is to read individual bytes */ |
|
|
|
|
# define READ_UINT32(ptr) (ptr[0]|ptr[1]<<8|ptr[2]<<16|ptr[3]<<24) |
|
|
|
|
# undef UNALIGNED_SAFE |
|
|
|
|
# define UNALIGNED_SAFE 1 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
|