diff options
| author | Talin <viridia@gmail.com> | 2012-02-18 21:00:49 +0000 |
|---|---|---|
| committer | Talin <viridia@gmail.com> | 2012-02-18 21:00:49 +0000 |
| commit | f2291c908bf53afec905dca6d3b4ebca908fbc91 (patch) | |
| tree | e61ef85fb55cc2f9daee2dddfc96145479508d6f /llvm/lib/Support/Hashing.cpp | |
| parent | 0b6b8e490c1a81a607bde6e4e92a8a5306c080ce (diff) | |
| download | bcm5719-llvm-f2291c908bf53afec905dca6d3b4ebca908fbc91.tar.gz bcm5719-llvm-f2291c908bf53afec905dca6d3b4ebca908fbc91.zip | |
Hashing.h - utilities for hashing various data types.
llvm-svn: 150890
Diffstat (limited to 'llvm/lib/Support/Hashing.cpp')
| -rw-r--r-- | llvm/lib/Support/Hashing.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/lib/Support/Hashing.cpp b/llvm/lib/Support/Hashing.cpp new file mode 100644 index 00000000000..89b84530afa --- /dev/null +++ b/llvm/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); + } +} + +} |

