From 5b8fd3c31a58b87b80605dca7a64fad6cb3f8a0f Mon Sep 17 00:00:00 2001 From: "aappleby@google.com" Date: Fri, 10 May 2013 19:30:25 +0000 Subject: Merge patch from benswick@ to make Murmur3 compile as plain C code. git-svn-id: http://smhasher.googlecode.com/svn/trunk@150 77a7d1d3-4c08-bdc2-d393-d5859734b01a --- MurmurHash3.cpp | 66 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/MurmurHash3.cpp b/MurmurHash3.cpp index 5a55b7a..aa7982d 100644 --- a/MurmurHash3.cpp +++ b/MurmurHash3.cpp @@ -52,12 +52,12 @@ inline uint64_t rotl64 ( uint64_t x, int8_t r ) // Block read - if your platform needs to do endian-swapping or can only // handle aligned reads, do the conversion here -FORCE_INLINE uint32_t getblock ( const uint32_t * p, int i ) +FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i ) { return p[i]; } -FORCE_INLINE uint64_t getblock ( const uint64_t * p, int i ) +FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, int i ) { return p[i]; } @@ -65,7 +65,7 @@ FORCE_INLINE uint64_t getblock ( const uint64_t * p, int i ) //----------------------------------------------------------------------------- // Finalization mix - force all bits of a hash block to avalanche -FORCE_INLINE uint32_t fmix ( uint32_t h ) +FORCE_INLINE uint32_t fmix32 ( uint32_t h ) { h ^= h >> 16; h *= 0x85ebca6b; @@ -78,7 +78,7 @@ FORCE_INLINE uint32_t fmix ( uint32_t h ) //---------- -FORCE_INLINE uint64_t fmix ( uint64_t k ) +FORCE_INLINE uint64_t fmix64 ( uint64_t k ) { k ^= k >> 33; k *= BIG_CONSTANT(0xff51afd7ed558ccd); @@ -109,7 +109,7 @@ void MurmurHash3_x86_32 ( const void * key, int len, for(int i = -nblocks; i; i++) { - uint32_t k1 = getblock(blocks,i); + uint32_t k1 = getblock32(blocks,i); k1 *= c1; k1 = ROTL32(k1,15); @@ -140,7 +140,7 @@ void MurmurHash3_x86_32 ( const void * key, int len, h1 ^= len; - h1 = fmix(h1); + h1 = fmix32(h1); *(uint32_t*)out = h1; } @@ -170,10 +170,10 @@ void MurmurHash3_x86_128 ( const void * key, const int len, for(int i = -nblocks; i; i++) { - uint32_t k1 = getblock(blocks,i*4+0); - uint32_t k2 = getblock(blocks,i*4+1); - uint32_t k3 = getblock(blocks,i*4+2); - uint32_t k4 = getblock(blocks,i*4+3); + uint32_t k1 = getblock32(blocks,i*4+0); + uint32_t k2 = getblock32(blocks,i*4+1); + uint32_t k3 = getblock32(blocks,i*4+2); + uint32_t k4 = getblock32(blocks,i*4+3); k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; @@ -236,10 +236,10 @@ void MurmurHash3_x86_128 ( const void * key, const int len, h1 += h2; h1 += h3; h1 += h4; h2 += h1; h3 += h1; h4 += h1; - h1 = fmix(h1); - h2 = fmix(h2); - h3 = fmix(h3); - h4 = fmix(h4); + h1 = fmix32(h1); + h2 = fmix32(h2); + h3 = fmix32(h3); + h4 = fmix32(h4); h1 += h2; h1 += h3; h1 += h4; h2 += h1; h3 += h1; h4 += h1; @@ -271,8 +271,8 @@ void MurmurHash3_x64_128 ( const void * key, const int len, for(int i = 0; i < nblocks; i++) { - uint64_t k1 = getblock(blocks,i*2+0); - uint64_t k2 = getblock(blocks,i*2+1); + uint64_t k1 = getblock64(blocks,i*2+0); + uint64_t k2 = getblock64(blocks,i*2+1); k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; @@ -293,23 +293,23 @@ void MurmurHash3_x64_128 ( const void * key, const int len, switch(len & 15) { - case 15: k2 ^= uint64_t(tail[14]) << 48; - case 14: k2 ^= uint64_t(tail[13]) << 40; - case 13: k2 ^= uint64_t(tail[12]) << 32; - case 12: k2 ^= uint64_t(tail[11]) << 24; - case 11: k2 ^= uint64_t(tail[10]) << 16; - case 10: k2 ^= uint64_t(tail[ 9]) << 8; - case 9: k2 ^= uint64_t(tail[ 8]) << 0; + case 15: k2 ^= ((uint64_t)tail[14]) << 48; + case 14: k2 ^= ((uint64_t)tail[13]) << 40; + case 13: k2 ^= ((uint64_t)tail[12]) << 32; + case 12: k2 ^= ((uint64_t)tail[11]) << 24; + case 11: k2 ^= ((uint64_t)tail[10]) << 16; + case 10: k2 ^= ((uint64_t)tail[ 9]) << 8; + case 9: k2 ^= ((uint64_t)tail[ 8]) << 0; k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - case 8: k1 ^= uint64_t(tail[ 7]) << 56; - case 7: k1 ^= uint64_t(tail[ 6]) << 48; - case 6: k1 ^= uint64_t(tail[ 5]) << 40; - case 5: k1 ^= uint64_t(tail[ 4]) << 32; - case 4: k1 ^= uint64_t(tail[ 3]) << 24; - case 3: k1 ^= uint64_t(tail[ 2]) << 16; - case 2: k1 ^= uint64_t(tail[ 1]) << 8; - case 1: k1 ^= uint64_t(tail[ 0]) << 0; + case 8: k1 ^= ((uint64_t)tail[ 7]) << 56; + case 7: k1 ^= ((uint64_t)tail[ 6]) << 48; + case 6: k1 ^= ((uint64_t)tail[ 5]) << 40; + case 5: k1 ^= ((uint64_t)tail[ 4]) << 32; + case 4: k1 ^= ((uint64_t)tail[ 3]) << 24; + case 3: k1 ^= ((uint64_t)tail[ 2]) << 16; + case 2: k1 ^= ((uint64_t)tail[ 1]) << 8; + case 1: k1 ^= ((uint64_t)tail[ 0]) << 0; k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; }; @@ -321,8 +321,8 @@ void MurmurHash3_x64_128 ( const void * key, const int len, h1 += h2; h2 += h1; - h1 = fmix(h1); - h2 = fmix(h2); + h1 = fmix64(h1); + h2 = fmix64(h2); h1 += h2; h2 += h1; -- cgit v1.2.3 From b52816cce35fbfdda7d56c533cf53d15201513e3 Mon Sep 17 00:00:00 2001 From: "aappleby@google.com" Date: Mon, 30 Dec 2013 21:23:01 +0000 Subject: Merge patch to fix build under VS2010 git-svn-id: http://smhasher.googlecode.com/svn/trunk@151 77a7d1d3-4c08-bdc2-d393-d5859734b01a --- MurmurHash1.h | 4 ++-- MurmurHash2.h | 4 ++-- MurmurHash3.h | 4 ++-- pstdint.h | 32 ++++++++++++++++++-------------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/MurmurHash1.h b/MurmurHash1.h index 93b08c3..24e1ad3 100644 --- a/MurmurHash1.h +++ b/MurmurHash1.h @@ -10,10 +10,10 @@ // Microsoft Visual Studio -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (_MSC_VER < 1600) typedef unsigned char uint8_t; -typedef unsigned long uint32_t; +typedef unsigned int uint32_t; typedef unsigned __int64 uint64_t; // Other compilers diff --git a/MurmurHash2.h b/MurmurHash2.h index 32993c2..6d289ed 100644 --- a/MurmurHash2.h +++ b/MurmurHash2.h @@ -10,10 +10,10 @@ // Microsoft Visual Studio -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (_MSC_VER < 1600) typedef unsigned char uint8_t; -typedef unsigned long uint32_t; +typedef unsigned int uint32_t; typedef unsigned __int64 uint64_t; // Other compilers diff --git a/MurmurHash3.h b/MurmurHash3.h index 54e9d3f..e1c6d34 100644 --- a/MurmurHash3.h +++ b/MurmurHash3.h @@ -10,10 +10,10 @@ // Microsoft Visual Studio -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (_MSC_VER < 1600) typedef unsigned char uint8_t; -typedef unsigned long uint32_t; +typedef unsigned int uint32_t; typedef unsigned __int64 uint64_t; // Other compilers diff --git a/pstdint.h b/pstdint.h index 43dce62..8bd4ad7 100644 --- a/pstdint.h +++ b/pstdint.h @@ -376,18 +376,20 @@ # define UINT32_MAX (0xffffffffUL) #endif #ifndef uint32_t -#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S) - typedef unsigned long uint32_t; -# define UINT32_C(v) v ## UL -# ifndef PRINTF_INT32_MODIFIER -# define PRINTF_INT32_MODIFIER "l" -# endif -#elif (UINT_MAX == UINT32_MAX) +// Try the 'natural' int type first. +// This is for compatibility with the stdint.h available on Windows. +#if (UINT_MAX == UINT32_MAX) && !defined (S_SPLINT_S) typedef unsigned int uint32_t; # ifndef PRINTF_INT32_MODIFIER # define PRINTF_INT32_MODIFIER "" # endif # define UINT32_C(v) v ## U +#elif (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S) + typedef unsigned long uint32_t; +# define UINT32_C(v) v ## UL +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "l" +# endif #elif (USHRT_MAX == UINT32_MAX) typedef unsigned short uint32_t; # define UINT32_C(v) ((unsigned short) (v)) @@ -406,18 +408,20 @@ # define INT32_MIN INT32_C(0x80000000) #endif #ifndef int32_t -#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S) - typedef signed long int32_t; -# define INT32_C(v) v ## L -# ifndef PRINTF_INT32_MODIFIER -# define PRINTF_INT32_MODIFIER "l" -# endif -#elif (INT_MAX == INT32_MAX) +// Try the 'natural' int type first. +// This is for compatibility with the stdint.h available on Windows. +#if (INT_MAX == INT32_MAX) && !defined (S_SPLINT_S) typedef signed int int32_t; # define INT32_C(v) v # ifndef PRINTF_INT32_MODIFIER # define PRINTF_INT32_MODIFIER "" # endif +#elif (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S) + typedef signed long int32_t; +# define INT32_C(v) v ## L +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "l" +# endif #elif (SHRT_MAX == INT32_MAX) typedef signed short int32_t; # define INT32_C(v) ((short) (v)) -- cgit v1.2.3