[llvm-commits] [llvm] r151892 - /llvm/trunk/include/llvm/ADT/Hashing.h

Chandler Carruth chandlerc at gmail.com
Fri Mar 2 03:16:10 PST 2012


Author: chandlerc
Date: Fri Mar  2 05:16:10 2012
New Revision: 151892

URL: http://llvm.org/viewvc/llvm-project?rev=151892&view=rev
Log:
Make the hashing algorithm Endian neutral. This is a bit annoying, but
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.

Modified:
    llvm/trunk/include/llvm/ADT/Hashing.h

Modified: llvm/trunk/include/llvm/ADT/Hashing.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Hashing.h?rev=151892&r1=151891&r2=151892&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Hashing.h (original)
+++ llvm/trunk/include/llvm/ADT/Hashing.h Fri Mar  2 05:16:10 2012
@@ -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 @@
 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;
 }
 





More information about the llvm-commits mailing list