Blender
V3.3
source
blender
blenlib
intern
hash_mm3.c
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0-or-later
2
* Copyright 2018 Blender Foundation. */
3
15
#include "
BLI_compiler_attrs.h
"
16
#include "
BLI_compiler_compat.h
"
17
#include "
BLI_hash_mm3.h
"
/* own include */
18
19
#if defined(_MSC_VER)
20
# include <stdlib.h>
21
# define ROTL32(x, y) _rotl(x, y)
22
# define BIG_CONSTANT(x) (x)
23
24
/* Other compilers */
25
#else
/* defined(_MSC_VER) */
26
static
inline
uint32_t
rotl32
(
uint32_t
x
,
int8_t
r
)
27
{
28
return
(
x
<<
r
) | (
x
>> (32 -
r
));
29
}
30
# define ROTL32(x, y) rotl32(x, y)
31
# define BIG_CONSTANT(x) (x##LLU)
32
#endif
/* !defined(_MSC_VER) */
33
34
/* Block read - if your platform needs to do endian-swapping or can only
35
* handle aligned reads, do the conversion here
36
*/
37
38
BLI_INLINE
uint32_t
getblock32
(
const
uint32_t
*p,
int
i)
39
{
40
return
p[i];
41
}
42
43
BLI_INLINE
uint64_t
getblock64
(
const
uint64_t
*p,
int
i)
44
{
45
return
p[i];
46
}
47
48
/* Finalization mix - force all bits of a hash block to avalanche */
49
50
BLI_INLINE
uint32_t
fmix32
(
uint32_t
h)
51
{
52
h ^= h >> 16;
53
h *= 0x85ebca6b;
54
h ^= h >> 13;
55
h *= 0xc2b2ae35;
56
h ^= h >> 16;
57
58
return
h;
59
}
60
61
BLI_INLINE
uint64_t
fmix64
(
uint64_t
k)
62
{
63
k ^= k >> 33;
64
k *=
BIG_CONSTANT
(0xff51afd7ed558ccd);
65
k ^= k >> 33;
66
k *=
BIG_CONSTANT
(0xc4ceb9fe1a85ec53);
67
k ^= k >> 33;
68
69
return
k;
70
}
71
72
uint32_t
BLI_hash_mm3
(
const
unsigned
char
*
data
,
size_t
len
,
uint32_t
seed
)
73
{
74
const
uint8_t
*in_data = (
const
uint8_t
*)
data
;
75
const
int
nblocks =
len
/ 4;
76
77
uint32_t
h1 =
seed
;
78
79
const
uint32_t
c1 = 0xcc9e2d51;
80
const
uint32_t
c2 = 0x1b873593;
81
82
/* body */
83
84
const
uint32_t
*blocks = (
const
uint32_t
*)(in_data + nblocks * 4);
85
86
for
(
int
i = -nblocks; i; i++) {
87
uint32_t
k1 =
getblock32
(blocks, i);
88
89
k1 *= c1;
90
k1 =
ROTL32
(k1, 15);
91
k1 *= c2;
92
93
h1 ^= k1;
94
h1 =
ROTL32
(h1, 13);
95
h1 = h1 * 5 + 0xe6546b64;
96
}
97
98
/* tail */
99
100
const
uint8_t
*tail = (
const
uint8_t
*)(in_data + nblocks * 4);
101
102
uint32_t
k1 = 0;
103
104
switch
(
len
& 3) {
105
case
3:
106
k1 ^= tail[2] << 16;
107
ATTR_FALLTHROUGH
;
108
case
2:
109
k1 ^= tail[1] << 8;
110
ATTR_FALLTHROUGH
;
111
case
1:
112
k1 ^= tail[0];
113
k1 *= c1;
114
k1 =
ROTL32
(k1, 15);
115
k1 *= c2;
116
h1 ^= k1;
117
}
118
119
/* finalization */
120
121
h1 ^=
len
;
122
123
h1 =
fmix32
(h1);
124
125
return
h1;
126
}
BLI_compiler_attrs.h
ATTR_FALLTHROUGH
#define ATTR_FALLTHROUGH
Definition:
BLI_compiler_attrs.h:75
BLI_compiler_compat.h
BLI_INLINE
#define BLI_INLINE
Definition:
BLI_compiler_compat.h:36
x
x
Definition:
BLI_expr_pylike_eval_test.cc:342
BLI_hash_mm3.h
r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
Definition:
GPU_legacy_stubs.h:431
data
data
Definition:
bmesh_operator_api_inline.h:157
seed
static unsigned long seed
Definition:
btSoftBody.h:39
len
int len
Definition:
draw_manager.c:108
getblock32
BLI_INLINE uint32_t getblock32(const uint32_t *p, int i)
Definition:
hash_mm3.c:38
getblock64
BLI_INLINE uint64_t getblock64(const uint64_t *p, int i)
Definition:
hash_mm3.c:43
BLI_hash_mm3
uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed)
Definition:
hash_mm3.c:72
rotl32
static uint32_t rotl32(uint32_t x, int8_t r)
Definition:
hash_mm3.c:26
fmix32
BLI_INLINE uint32_t fmix32(uint32_t h)
Definition:
hash_mm3.c:50
BIG_CONSTANT
#define BIG_CONSTANT(x)
Definition:
hash_mm3.c:31
ROTL32
#define ROTL32(x, y)
Definition:
hash_mm3.c:30
fmix64
BLI_INLINE uint64_t fmix64(uint64_t k)
Definition:
hash_mm3.c:61
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 Tue Oct 22 2024 13:18:25 for Blender by
doxygen
1.9.1