Blender V5.3
hash_mm3.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#include "BLI_compiler_attrs.hh"
18#include "BLI_hash_mm3.hh" /* own include */
19
20namespace blender {
21
22#if defined(_MSC_VER)
23# include <stdlib.h>
24# define ROTL32(x, y) _rotl(x, y)
25# define BIG_CONSTANT(x) (x)
26
27/* Other compilers */
28#else /* defined(_MSC_VER) */
29static inline uint32_t rotl32(uint32_t x, int8_t r)
30{
31 return (x << r) | (x >> (32 - r));
32}
33# define ROTL32(x, y) rotl32(x, y)
34# define BIG_CONSTANT(x) (x##LLU)
35#endif /* !defined(_MSC_VER) */
36
37/* Block read - if your platform needs to do endian-swapping or can only
38 * handle aligned reads, do the conversion here
39 */
40
42{
43 return p[i];
44}
45
47{
48 return p[i];
49}
50
51/* Finalization mix - force all bits of a hash block to avalanche */
52
54{
55 h ^= h >> 16;
56 h *= 0x85ebca6b;
57 h ^= h >> 13;
58 h *= 0xc2b2ae35;
59 h ^= h >> 16;
60
61 return h;
62}
63
65{
66 k ^= k >> 33;
67 k *= BIG_CONSTANT(0xff51afd7ed558ccd);
68 k ^= k >> 33;
69 k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
70 k ^= k >> 33;
71
72 return k;
73}
74
76{
77 const uint8_t *in_data = static_cast<const uint8_t *>(data);
78 const int nblocks = len / 4;
79
80 uint32_t h1 = seed;
81
82 const uint32_t c1 = 0xcc9e2d51;
83 const uint32_t c2 = 0x1b873593;
84
85 /* body */
86
87 const uint32_t *blocks = reinterpret_cast<const uint32_t *>(in_data + nblocks * 4);
88
89 for (int i = -nblocks; i; i++) {
90 uint32_t k1 = getblock32(blocks, i);
91
92 k1 *= c1;
93 k1 = ROTL32(k1, 15);
94 k1 *= c2;
95
96 h1 ^= k1;
97 h1 = ROTL32(h1, 13);
98 h1 = h1 * 5 + 0xe6546b64;
99 }
100
101 /* tail */
102
103 const uint8_t *tail = static_cast<const uint8_t *>(in_data + nblocks * 4);
104
105 uint32_t k1 = 0;
106
107 switch (len & 3) {
108 case 3:
109 k1 ^= tail[2] << 16;
111 case 2:
112 k1 ^= tail[1] << 8;
114 case 1:
115 k1 ^= tail[0];
116 k1 *= c1;
117 k1 = ROTL32(k1, 15);
118 k1 *= c2;
119 h1 ^= k1;
120 }
121
122 /* finalization */
123
124 h1 ^= len;
125
126 h1 = fmix32(h1);
127
128 return h1;
129}
130
131} // namespace blender
#define ATTR_FALLTHROUGH
#define BLI_INLINE
#define BIG_CONSTANT(x)
Definition hash_mm3.cc:34
#define ROTL32(x, y)
Definition hash_mm3.cc:33
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
static uint32_t rotl32(uint32_t x, int8_t r)
Definition hash_mm3.cc:29
BLI_INLINE uint32_t fmix32(uint32_t h)
Definition hash_mm3.cc:53
uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed)
Definition hash_mm3.cc:75
BLI_INLINE uint64_t getblock64(const uint64_t *p, int i)
Definition hash_mm3.cc:46
BLI_INLINE uint32_t getblock32(const uint32_t *p, int i)
Definition hash_mm3.cc:41
unsigned int uint32_t
Definition BKE_text.h:81
unsigned char uchar
Definition BKE_text.h:58
BMesh const char void * data
unsigned char uint8_t
Definition BKE_text.h:79
BLI_INLINE uint64_t fmix64(uint64_t k)
Definition hash_mm3.cc:64
signed char int8_t
Definition BKE_text.h:76