mirror of https://github.com/mgba-emu/mgba.git
Util: Reformat hashing and let it use 64-bit regions
This commit is contained in:
parent
6b189fe249
commit
0035b5a22b
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
CXX_GUARD_START
|
CXX_GUARD_START
|
||||||
|
|
||||||
uint32_t hash32(const void* key, int len, uint32_t seed);
|
uint32_t hash32(const void* key, size_t len, uint32_t seed);
|
||||||
|
|
||||||
CXX_GUARD_END
|
CXX_GUARD_END
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ static inline uint32_t rotl32 ( uint32_t x, int8_t r ) {
|
||||||
// Block read - if your platform needs to do endian-swapping or can only
|
// Block read - if your platform needs to do endian-swapping or can only
|
||||||
// handle aligned reads, do the conversion here
|
// handle aligned reads, do the conversion here
|
||||||
|
|
||||||
static FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i ) {
|
static FORCE_INLINE uint32_t getblock32(const uint32_t* p, ssize_t i) {
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
LOAD_32LE(ret, i << 2, p);
|
LOAD_32LE(ret, i << 2, p);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -48,7 +48,7 @@ static FORCE_INLINE uint32_t fmix32 (uint32_t h) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
uint32_t hash32(const void* key, int len, uint32_t seed) {
|
uint32_t hash32(const void* key, size_t len, uint32_t seed) {
|
||||||
const uint8_t* data = (const uint8_t*) key;
|
const uint8_t* data = (const uint8_t*) key;
|
||||||
const int nblocks = len / 4;
|
const int nblocks = len / 4;
|
||||||
|
|
||||||
|
@ -63,8 +63,7 @@ uint32_t hash32(const void* key, int len, uint32_t seed) {
|
||||||
const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4);
|
const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i = -nblocks; i; i++)
|
for (i = -nblocks; i; i++) {
|
||||||
{
|
|
||||||
uint32_t k1 = getblock32(blocks, i);
|
uint32_t k1 = getblock32(blocks, i);
|
||||||
|
|
||||||
k1 *= c1;
|
k1 *= c1;
|
||||||
|
@ -83,8 +82,7 @@ uint32_t hash32(const void* key, int len, uint32_t seed) {
|
||||||
|
|
||||||
uint32_t k1 = 0;
|
uint32_t k1 = 0;
|
||||||
|
|
||||||
switch(len & 3)
|
switch(len & 3) {
|
||||||
{
|
|
||||||
case 3:
|
case 3:
|
||||||
k1 ^= tail[2] << 16;
|
k1 ^= tail[2] << 16;
|
||||||
// Fall through
|
// Fall through
|
||||||
|
@ -93,7 +91,10 @@ uint32_t hash32(const void* key, int len, uint32_t seed) {
|
||||||
// Fall through
|
// Fall through
|
||||||
case 1:
|
case 1:
|
||||||
k1 ^= tail[0];
|
k1 ^= tail[0];
|
||||||
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
|
k1 *= c1;
|
||||||
|
k1 = ROTL32(k1, 15);
|
||||||
|
k1 *= c2;
|
||||||
|
h1 ^= k1;
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------
|
//----------
|
||||||
|
|
Loading…
Reference in New Issue