summaryrefslogtreecommitdiff
path: root/src/common/hash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/hash.cpp')
-rw-r--r--src/common/hash.cpp141
1 files changed, 0 insertions, 141 deletions
diff --git a/src/common/hash.cpp b/src/common/hash.cpp
deleted file mode 100644
index a02e9e5b9..000000000
--- a/src/common/hash.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#if defined(_MSC_VER)
6#include <stdlib.h>
7#endif
8#include "common/common_funcs.h"
9#include "common/common_types.h"
10#include "common/hash.h"
11
12namespace Common {
13
14// MurmurHash3 was written by Austin Appleby, and is placed in the public
15// domain. The author hereby disclaims copyright to this source code.
16
17// Block read - if your platform needs to do endian-swapping or can only handle aligned reads, do
18// the conversion here
19static FORCE_INLINE u64 getblock64(const u64* p, size_t i) {
20 return p[i];
21}
22
23// Finalization mix - force all bits of a hash block to avalanche
24static FORCE_INLINE u64 fmix64(u64 k) {
25 k ^= k >> 33;
26 k *= 0xff51afd7ed558ccdllu;
27 k ^= k >> 33;
28 k *= 0xc4ceb9fe1a85ec53llu;
29 k ^= k >> 33;
30
31 return k;
32}
33
34// This is the 128-bit variant of the MurmurHash3 hash function that is targeted for 64-bit
35// platforms (MurmurHash3_x64_128). It was taken from:
36// https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp
37void MurmurHash3_128(const void* key, size_t len, u32 seed, void* out) {
38 const u8* data = (const u8*)key;
39 const size_t nblocks = len / 16;
40
41 u64 h1 = seed;
42 u64 h2 = seed;
43
44 const u64 c1 = 0x87c37b91114253d5llu;
45 const u64 c2 = 0x4cf5ad432745937fllu;
46
47 // Body
48
49 const u64* blocks = (const u64*)(data);
50
51 for (size_t i = 0; i < nblocks; i++) {
52 u64 k1 = getblock64(blocks, i * 2 + 0);
53 u64 k2 = getblock64(blocks, i * 2 + 1);
54
55 k1 *= c1;
56 k1 = _rotl64(k1, 31);
57 k1 *= c2;
58 h1 ^= k1;
59
60 h1 = _rotl64(h1, 27);
61 h1 += h2;
62 h1 = h1 * 5 + 0x52dce729;
63
64 k2 *= c2;
65 k2 = _rotl64(k2, 33);
66 k2 *= c1;
67 h2 ^= k2;
68
69 h2 = _rotl64(h2, 31);
70 h2 += h1;
71 h2 = h2 * 5 + 0x38495ab5;
72 }
73
74 // Tail
75
76 const u8* tail = (const u8*)(data + nblocks * 16);
77
78 u64 k1 = 0;
79 u64 k2 = 0;
80
81 switch (len & 15) {
82 case 15:
83 k2 ^= ((u64)tail[14]) << 48;
84 case 14:
85 k2 ^= ((u64)tail[13]) << 40;
86 case 13:
87 k2 ^= ((u64)tail[12]) << 32;
88 case 12:
89 k2 ^= ((u64)tail[11]) << 24;
90 case 11:
91 k2 ^= ((u64)tail[10]) << 16;
92 case 10:
93 k2 ^= ((u64)tail[9]) << 8;
94 case 9:
95 k2 ^= ((u64)tail[8]) << 0;
96 k2 *= c2;
97 k2 = _rotl64(k2, 33);
98 k2 *= c1;
99 h2 ^= k2;
100
101 case 8:
102 k1 ^= ((u64)tail[7]) << 56;
103 case 7:
104 k1 ^= ((u64)tail[6]) << 48;
105 case 6:
106 k1 ^= ((u64)tail[5]) << 40;
107 case 5:
108 k1 ^= ((u64)tail[4]) << 32;
109 case 4:
110 k1 ^= ((u64)tail[3]) << 24;
111 case 3:
112 k1 ^= ((u64)tail[2]) << 16;
113 case 2:
114 k1 ^= ((u64)tail[1]) << 8;
115 case 1:
116 k1 ^= ((u64)tail[0]) << 0;
117 k1 *= c1;
118 k1 = _rotl64(k1, 31);
119 k1 *= c2;
120 h1 ^= k1;
121 };
122
123 // Finalization
124
125 h1 ^= len;
126 h2 ^= len;
127
128 h1 += h2;
129 h2 += h1;
130
131 h1 = fmix64(h1);
132 h2 = fmix64(h2);
133
134 h1 += h2;
135 h2 += h1;
136
137 ((u64*)out)[0] = h1;
138 ((u64*)out)[1] = h2;
139}
140
141} // namespace Common