mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-10 22:04:25 -06:00
Core: Mem
git-svn-id: svn://ultimatepp.org/upp/trunk@14523 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
e21fe262af
commit
07c9863003
3 changed files with 41 additions and 35 deletions
|
|
@ -85,4 +85,40 @@ bool memeq64(const void *p, const void *q, size_t len) { return inline_memeq64_a
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef CPU_UNALIGNED
|
||||
|
||||
NOUBSAN // CPU supports unaligned memory access
|
||||
hash_t memhash(const void *ptr, size_t count)
|
||||
{
|
||||
unsigned hash = 1234567890U;
|
||||
|
||||
const unsigned *ds = (unsigned *)ptr;
|
||||
const unsigned *de = ds + (count >> 2);
|
||||
while(ds < de)
|
||||
hash = ((hash << 5) - hash) ^ *ds++;
|
||||
|
||||
const byte *s = (byte *)ds;
|
||||
const byte *e = s + (count & 3);
|
||||
while(s < e)
|
||||
hash = ((hash << 5) - hash) ^ *s++;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
hash_t memhash(const void *ptr, size_t count)
|
||||
{
|
||||
unsigned hash = 1234567890U;
|
||||
|
||||
const byte *s = (byte *)ptr;
|
||||
const byte *e = s + count;
|
||||
while(s < e)
|
||||
hash = ((hash << 5) - hash) ^ *s++;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
|
@ -615,38 +615,4 @@ int inline_memcmp_aligned(const char *a, const char *b, size_t len)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CPU_UNALIGNED
|
||||
|
||||
NOUBSAN // CPU supports unaligned memory access
|
||||
inline hash_t memhash(const void *ptr, size_t count)
|
||||
{
|
||||
unsigned hash = 1234567890U;
|
||||
|
||||
const unsigned *ds = (unsigned *)ptr;
|
||||
const unsigned *de = ds + (count >> 2);
|
||||
while(ds < de)
|
||||
hash = ((hash << 5) - hash) ^ *ds++;
|
||||
|
||||
const byte *s = (byte *)ds;
|
||||
const byte *e = s + (count & 3);
|
||||
while(s < e)
|
||||
hash = ((hash << 5) - hash) ^ *s++;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline hash_t memhash(const void *ptr, size_t count)
|
||||
{
|
||||
unsigned hash = 1234567890U;
|
||||
|
||||
const byte *s = (byte *)ptr;
|
||||
const byte *e = s + count;
|
||||
while(s < e)
|
||||
hash = ((hash << 5) - hash) ^ *s++;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endif
|
||||
hash_t memhash(const void *ptr, size_t count);
|
||||
|
|
|
|||
|
|
@ -158,6 +158,10 @@ inline dword FoldHash(dword h)
|
|||
return SwapEndian32(0xa3613c16 * h);
|
||||
}
|
||||
|
||||
#define HASH32_CONST1 0xf7c21089
|
||||
#define HASH32_CONST2 0xc85abc8d
|
||||
#define HASH32_CONST3 0x8642b0fe
|
||||
|
||||
#define HASH64_CONST1 I64(0xf7c21089bee7c0a5)
|
||||
#define HASH64_CONST2 I64(0xc85abc8da7534a4d)
|
||||
#define HASH64_CONST3 I64(0x8642b0fe3e86671b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue