Make the hashing algorithm Endian neutral. This is a bit annoying, but
authorChandler Carruth <chandlerc@gmail.com>
Fri, 2 Mar 2012 11:16:10 +0000 (11:16 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 2 Mar 2012 11:16:10 +0000 (11:16 +0000)
folks who know something about PPC tell me that the byte swap is crazy
fast and without this the bit mixture would actually be different. It
might not be worse, but I've not measured it and so I'd rather not trust
it. This way, the algorithm is identical on both endianness hosts. I'll
look into any performance issues etc stemming from this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151892 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/Hashing.h

index 7fbe5bb0ca275c901aaee8f059d7028e871f3929..2c270e4ffc59742d2c789f9010ffaca59236ecfe 100644 (file)
@@ -47,6 +47,8 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/type_traits.h"
 #include <algorithm>
 #include <cassert>
@@ -149,12 +151,16 @@ namespace detail {
 inline uint64_t fetch64(const char *p) {
   uint64_t result;
   memcpy(&result, p, sizeof(result));
+  if (sys::isBigEndianHost())
+    return sys::SwapByteOrder(result);
   return result;
 }
 
 inline uint32_t fetch32(const char *p) {
   uint32_t result;
   memcpy(&result, p, sizeof(result));
+  if (sys::isBigEndianHost())
+    return sys::SwapByteOrder(result);
   return result;
 }