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