@@ -78,59 +78,30 @@ void hashMurmurx86 ( const void * key, const int len, const uint seed, void * ou
78
78
* ROTL32(x,r) Rotate x left by r bits
79
79
*/
80
80
81
- /* Convention is to define __BYTE_ORDER == to one of these values */
82
- #if !defined(__BIG_ENDIAN)
83
- #define __BIG_ENDIAN 4321
84
- #endif
85
- #if !defined(__LITTLE_ENDIAN)
86
- #define __LITTLE_ENDIAN 1234
87
- #endif
88
-
89
- /* I386 */
90
- #if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386)
91
- #define __BYTE_ORDER __LITTLE_ENDIAN
92
- #define UNALIGNED_SAFE
93
- #endif
94
-
95
- /* gcc 'may' define __LITTLE_ENDIAN__ or __BIG_ENDIAN__ to 1 (Note the trailing __),
96
- * or even _LITTLE_ENDIAN or _BIG_ENDIAN (Note the single _ prefix) */
97
- #if !defined(__BYTE_ORDER)
98
- #if defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__==1 || defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN==1
99
- #define __BYTE_ORDER __LITTLE_ENDIAN
100
- #elif defined(__BIG_ENDIAN__) && __BIG_ENDIAN__==1 || defined(_BIG_ENDIAN) && _BIG_ENDIAN==1
101
- #define __BYTE_ORDER __BIG_ENDIAN
102
- #endif
81
+ #if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386))
82
+ # define UNALIGNED_SAFE 1
103
83
#endif
104
84
105
- /* gcc (usually) defines xEL/EB macros for ARM and MIPS endianess */
106
- #if !defined(__BYTE_ORDER)
107
- #if defined(__ARMEL__) || defined(__MIPSEL__)
108
- #define __BYTE_ORDER __LITTLE_ENDIAN
109
- #endif
110
- #if defined(__ARMEB__) || defined(__MIPSEB__)
111
- #define __BYTE_ORDER __BIG_ENDIAN
112
- #endif
85
+ #ifndef UNALIGNED_SAFE
86
+ # define UNALIGNED_SAFE 1
87
+ #elif defined(UNALIGNED_SAFE) && !UNALIGNED_SAFE == 0
88
+ # undef UNALIGNED_SAFE
113
89
#endif
114
90
115
91
/* Now find best way we can to READ_UINT32 */
116
- #if __BYTE_ORDER==__LITTLE_ENDIAN
117
- /* CPU endian matches murmurhash algorithm, so read 32-bit word directly */
118
- #define READ_UINT32 (ptr ) (*((uint32_t *)(ptr)))
119
- #elif __BYTE_ORDER==__BIG_ENDIAN
120
- /* TODO: Add additional cases below where a compiler provided bswap32 is available */
121
- #if defined(__GNUC__) && (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3))
122
- #define READ_UINT32 (ptr ) (__builtin_bswap32(*((uint32_t *)(ptr))))
123
- #else
124
- /* Without a known fast bswap32 we're just as well off doing this */
125
- #define READ_UINT32 (ptr ) (ptr[0 ]|ptr[1 ]<<8 |ptr[2 ]<<16 |ptr[3 ]<<24 )
126
- #define UNALIGNED_SAFE
92
+ #if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386)) \
93
+ || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
94
+ # define READ_UINT32 (ptr ) (*((uint32_t *)(ptr)))
95
+ #elif (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
96
+ && defined(__GNUC__) && (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3 ))
97
+ # define READ_UINT32 (ptr ) (__builtin_bswap32(*((uint32_t *)(ptr))))
127
98
#endif
128
- #else
129
- /* Unknown endianess so last resort is to read individual bytes */
130
- #define READ_UINT32 (ptr ) (ptr[0 ]|ptr[1 ]<<8 |ptr[2 ]<<16 |ptr[3 ]<<24 )
131
99
132
- /* Since we're not doing word-reads we can skip the messing about with realignment */
133
- #define UNALIGNED_SAFE
100
+ #ifndef READ_UINT32
101
+ /* Unknown endianess so last resort is to read individual bytes */
102
+ # define READ_UINT32 (ptr ) (ptr[0 ]|ptr[1 ]<<8 |ptr[2 ]<<16 |ptr[3 ]<<24 )
103
+ # undef UNALIGNED_SAFE
104
+ # define UNALIGNED_SAFE 1
134
105
#endif
135
106
136
107
/* -----------------------------------------------------------------------------
0 commit comments