Blender
V2.93
source
blender
blenlib
intern
hash_mm3.c
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or
3
* modify it under the terms of the GNU General Public License
4
* as published by the Free Software Foundation; either version 2
5
* of the License, or (at your option) any later version.
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software Foundation,
14
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
* Copyright (C) 2018 Blender Foundation.
16
*/
17
29
#include "
BLI_compiler_attrs.h
"
30
#include "
BLI_compiler_compat.h
"
31
#include "
BLI_hash_mm3.h
"
/* own include */
32
33
#if defined(_MSC_VER)
34
# include <stdlib.h>
35
# define ROTL32(x, y) _rotl(x, y)
36
# define BIG_CONSTANT(x) (x)
37
38
/* Other compilers */
39
#else
/* defined(_MSC_VER) */
40
static
inline
uint32_t
rotl32
(
uint32_t
x
,
int8_t
r
)
41
{
42
return
(
x
<<
r
) | (
x
>> (32 -
r
));
43
}
44
# define ROTL32(x, y) rotl32(x, y)
45
# define BIG_CONSTANT(x) (x##LLU)
46
#endif
/* !defined(_MSC_VER) */
47
48
/* Block read - if your platform needs to do endian-swapping or can only
49
* handle aligned reads, do the conversion here
50
*/
51
52
BLI_INLINE
uint32_t
getblock32
(
const
uint32_t
*p,
int
i)
53
{
54
return
p[i];
55
}
56
57
BLI_INLINE
uint64_t
getblock64
(
const
uint64_t
*p,
int
i)
58
{
59
return
p[i];
60
}
61
62
/* Finalization mix - force all bits of a hash block to avalanche */
63
64
BLI_INLINE
uint32_t
fmix32
(
uint32_t
h)
65
{
66
h ^= h >> 16;
67
h *= 0x85ebca6b;
68
h ^= h >> 13;
69
h *= 0xc2b2ae35;
70
h ^= h >> 16;
71
72
return
h;
73
}
74
75
BLI_INLINE
uint64_t
fmix64
(
uint64_t
k)
76
{
77
k ^= k >> 33;
78
k *=
BIG_CONSTANT
(0xff51afd7ed558ccd);
79
k ^= k >> 33;
80
k *=
BIG_CONSTANT
(0xc4ceb9fe1a85ec53);
81
k ^= k >> 33;
82
83
return
k;
84
}
85
86
uint32_t
BLI_hash_mm3
(
const
unsigned
char
*
data
,
size_t
len
,
uint32_t
seed
)
87
{
88
const
uint8_t
*in_data = (
const
uint8_t
*)
data
;
89
const
int
nblocks =
len
/ 4;
90
91
uint32_t
h1 =
seed
;
92
93
const
uint32_t
c1 = 0xcc9e2d51;
94
const
uint32_t
c2 = 0x1b873593;
95
96
/* body */
97
98
const
uint32_t
*blocks = (
const
uint32_t
*)(in_data + nblocks * 4);
99
100
for
(
int
i = -nblocks; i; i++) {
101
uint32_t
k1 =
getblock32
(blocks, i);
102
103
k1 *= c1;
104
k1 =
ROTL32
(k1, 15);
105
k1 *= c2;
106
107
h1 ^= k1;
108
h1 =
ROTL32
(h1, 13);
109
h1 = h1 * 5 + 0xe6546b64;
110
}
111
112
/* tail */
113
114
const
uint8_t
*tail = (
const
uint8_t
*)(in_data + nblocks * 4);
115
116
uint32_t
k1 = 0;
117
118
switch
(
len
& 3) {
119
case
3:
120
k1 ^= tail[2] << 16;
121
ATTR_FALLTHROUGH
;
122
case
2:
123
k1 ^= tail[1] << 8;
124
ATTR_FALLTHROUGH
;
125
case
1:
126
k1 ^= tail[0];
127
k1 *= c1;
128
k1 =
ROTL32
(k1, 15);
129
k1 *= c2;
130
h1 ^= k1;
131
}
132
133
/* finalization */
134
135
h1 ^=
len
;
136
137
h1 =
fmix32
(h1);
138
139
return
h1;
140
}
BLI_compiler_attrs.h
ATTR_FALLTHROUGH
#define ATTR_FALLTHROUGH
Definition:
BLI_compiler_attrs.h:91
BLI_compiler_compat.h
BLI_INLINE
#define BLI_INLINE
Definition:
BLI_compiler_compat.h:50
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:447
data
data
Definition:
bmesh_operator_api_inline.h:176
seed
static unsigned long seed
Definition:
btSoftBody.h:39
getblock32
BLI_INLINE uint32_t getblock32(const uint32_t *p, int i)
Definition:
hash_mm3.c:52
getblock64
BLI_INLINE uint64_t getblock64(const uint64_t *p, int i)
Definition:
hash_mm3.c:57
BLI_hash_mm3
uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed)
Definition:
hash_mm3.c:86
rotl32
static uint32_t rotl32(uint32_t x, int8_t r)
Definition:
hash_mm3.c:40
fmix32
BLI_INLINE uint32_t fmix32(uint32_t h)
Definition:
hash_mm3.c:64
BIG_CONSTANT
#define BIG_CONSTANT(x)
Definition:
hash_mm3.c:45
ROTL32
#define ROTL32(x, y)
Definition:
hash_mm3.c:44
fmix64
BLI_INLINE uint64_t fmix64(uint64_t k)
Definition:
hash_mm3.c:75
uint32_t
unsigned int uint32_t
Definition:
stdint.h:83
uint8_t
unsigned char uint8_t
Definition:
stdint.h:81
uint64_t
unsigned __int64 uint64_t
Definition:
stdint.h:93
int8_t
signed char int8_t
Definition:
stdint.h:78
len
uint len
Definition:
uvedit_unwrap_ops.c:1146
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1