summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraappleby@google.com <aappleby@google.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2011-04-05 00:15:28 +0000
committeraappleby@google.com <aappleby@google.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2011-04-05 00:15:28 +0000
commitf068a580c78997431304d9dcb22ba7d89c4333e7 (patch)
treea7ca741849c55439fd3c2a9b15d0878ce6622c55
parent4bbda98dc256abd514bb2011560cded111fd205b (diff)
downloadsrc-f068a580c78997431304d9dcb22ba7d89c4333e7.tar.gz
Make MurmurHash3.cpp compile standalone on GCC
git-svn-id: http://smhasher.googlecode.com/svn/trunk@124 77a7d1d3-4c08-bdc2-d393-d5859734b01a
-rw-r--r--MurmurHash3.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/MurmurHash3.cpp b/MurmurHash3.cpp
index 8f63772..5fcbe94 100644
--- a/MurmurHash3.cpp
+++ b/MurmurHash3.cpp
@@ -2,13 +2,51 @@
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
-#include "MurmurHash3.h"
-
// Note - The x86 and x64 versions do _not_ produce the same results, as the
// algorithms are optimized for their respective platforms. You can still
// compile and run any of them on any platform, but your performance with the
// non-native version will be less than optimal.
+//-----------------------------------------------------------------------------
+// Platform-specific functions and macros
+
+// Microsoft Visual Studio
+
+#if defined(_MSC_VER)
+
+#define FORCE_INLINE __forceinline
+
+#include <stdlib.h>
+
+#define ROTL32(x,y) _rotl(x,y)
+#define ROTL64(x,y) _rotl64(x,y)
+
+#define BIG_CONSTANT(x) (x)
+
+// Other compilers
+
+#else // defined(_MSC_VER)
+
+#include <stdint.h>
+
+#define FORCE_INLINE __attribute__((always_inline))
+
+inline uint32_t rotl32 ( uint32_t x, int8_t r )
+{
+ return (x << r) | (x >> (32 - r));
+}
+
+inline uint64_t rotl64 ( uint64_t x, int8_t r )
+{
+ return (x << r) | (x >> (64 - r));
+}
+
+#define ROTL32(x,y) rotl32(x,y)
+#define ROTL64(x,y) rotl64(x,y)
+
+#define BIG_CONSTANT(x) (x##LLU)
+
+#endif // !defined(_MSC_VER)
//-----------------------------------------------------------------------------
// Block read - if your platform needs to do endian-swapping or can only
@@ -294,3 +332,4 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
}
//-----------------------------------------------------------------------------
+