summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorTalin <viridia@gmail.com>2012-02-18 21:00:49 +0000
committerTalin <viridia@gmail.com>2012-02-18 21:00:49 +0000
commit1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52 (patch)
tree1565245621888b72e8961943ec306b4cecf78a7e /lib/Support
parentb155c23f98e45bf5a1f5e6329b46e8138dfef9ce (diff)
downloadllvm-1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52.tar.gz
llvm-1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52.tar.bz2
llvm-1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52.tar.xz
Hashing.h - utilities for hashing various data types.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/CMakeLists.txt1
-rw-r--r--lib/Support/Hashing.cpp46
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt
index 6cec47df67..0b69238274 100644
--- a/lib/Support/CMakeLists.txt
+++ b/lib/Support/CMakeLists.txt
@@ -26,6 +26,7 @@ add_llvm_library(LLVMSupport
FoldingSet.cpp
FormattedStream.cpp
GraphWriter.cpp
+ Hashing.cpp
IntEqClasses.cpp
IntervalMap.cpp
IntrusiveRefCntPtr.cpp
diff --git a/lib/Support/Hashing.cpp b/lib/Support/Hashing.cpp
new file mode 100644
index 0000000000..89b84530af
--- /dev/null
+++ b/lib/Support/Hashing.cpp
@@ -0,0 +1,46 @@
+//===-- llvm/ADT/Hashing.cpp - Utilities for hashing ------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/Hashing.h"
+
+namespace llvm {
+
+// Add a possibly unaligned sequence of bytes.
+void GeneralHash::addUnaligned(const uint8_t *I, const uint8_t *E) {
+ ptrdiff_t Length = E - I;
+ if (uintptr_t(I) & 3 == 0) {
+ while (Length > 3) {
+ mix(*reinterpret_cast<const uint32_t *>(I));
+ I += 4;
+ Length -= 4;
+ }
+ } else {
+ while (Length > 3) {
+ mix(
+ uint32_t(I[0]) +
+ (uint32_t(I[1]) << 8) +
+ (uint32_t(I[2]) << 16) +
+ (uint32_t(I[3]) << 24));
+ I += 4;
+ Length -= 4;
+ }
+ }
+
+ if (Length & 3) {
+ uint32_t Data = 0;
+ switch (Length & 3) {
+ case 3: Data |= uint32_t(I[2]) << 16; // fall through
+ case 2: Data |= uint32_t(I[1]) << 8; // fall through
+ case 1: Data |= uint32_t(I[0]); break;
+ }
+ mix(Data);
+ }
+}
+
+}