mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Fix some potential alignment issues
In ARM platforms we need data aligned for direct access. Use special tricks to access unaligned one.
This commit is contained in:
parent
cbe9f708a4
commit
ac3714aa8a
3 changed files with 49 additions and 38 deletions
|
|
@ -81,18 +81,12 @@ void MurmurHash3_x86_128(const void* data, size_t size, const uint8_t* seed, voi
|
|||
const uint32_t* blocks;
|
||||
const uint32_t* end;
|
||||
size_t size_remainder;
|
||||
uint32_t h1, h2, h3, h4;
|
||||
|
||||
uint32_t h1 = ((const uint32_t*)seed)[0];
|
||||
uint32_t h2 = ((const uint32_t*)seed)[1];
|
||||
uint32_t h3 = ((const uint32_t*)seed)[2];
|
||||
uint32_t h4 = ((const uint32_t*)seed)[3];
|
||||
|
||||
#if WORDS_BIGENDIAN
|
||||
h1 = util_swap32(h1);
|
||||
h2 = util_swap32(h2);
|
||||
h3 = util_swap32(h3);
|
||||
h4 = util_swap32(h4);
|
||||
#endif
|
||||
h1 = util_read32(seed + 0);
|
||||
h2 = util_read32(seed + 4);
|
||||
h3 = util_read32(seed + 8);
|
||||
h4 = util_read32(seed + 12);
|
||||
|
||||
nblocks = size / 16;
|
||||
blocks = data;
|
||||
|
|
@ -178,16 +172,9 @@ void MurmurHash3_x86_128(const void* data, size_t size, const uint8_t* seed, voi
|
|||
h1 += h2; h1 += h3; h1 += h4;
|
||||
h2 += h1; h3 += h1; h4 += h1;
|
||||
|
||||
#if WORDS_BIGENDIAN
|
||||
h1 = util_swap32(h1);
|
||||
h2 = util_swap32(h2);
|
||||
h3 = util_swap32(h3);
|
||||
h4 = util_swap32(h4);
|
||||
#endif
|
||||
|
||||
((uint32_t*)digest)[0] = h1;
|
||||
((uint32_t*)digest)[1] = h2;
|
||||
((uint32_t*)digest)[2] = h3;
|
||||
((uint32_t*)digest)[3] = h4;
|
||||
util_write32(digest + 0, h1);
|
||||
util_write32(digest + 4, h2);
|
||||
util_write32(digest + 8, h3);
|
||||
util_write32(digest + 12, h4);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,18 +116,12 @@ void SpookyHash128(const void* data, size_t size, const uint8_t* seed, uint8_t*
|
|||
const uint64_t* blocks;
|
||||
const uint64_t* end;
|
||||
size_t size_remainder;
|
||||
|
||||
#if WORDS_BIGENDIAN
|
||||
unsigned i;
|
||||
#endif
|
||||
|
||||
h9 = ((const uint64_t*)seed)[0];
|
||||
h10 = ((const uint64_t*)seed)[1];
|
||||
|
||||
#if WORDS_BIGENDIAN
|
||||
h9 = util_swap64(h9);
|
||||
h10 = util_swap64(h10);
|
||||
#endif
|
||||
h9 = util_read64(seed + 0);
|
||||
h10 = util_read64(seed + 8);
|
||||
|
||||
h0 = h3 = h6 = h9;
|
||||
h1 = h4 = h7 = h10;
|
||||
|
|
@ -160,15 +154,9 @@ void SpookyHash128(const void* data, size_t size, const uint8_t* seed, uint8_t*
|
|||
for (i = 0; i < sc_numVars; ++i)
|
||||
buf[i] = util_swap64(buf[i]);
|
||||
#endif
|
||||
|
||||
End(buf, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11);
|
||||
|
||||
#if WORDS_BIGENDIAN
|
||||
h0 = util_swap64(h0);
|
||||
h1 = util_swap64(h1);
|
||||
#endif
|
||||
|
||||
((uint64_t*)digest)[0] = h0;
|
||||
((uint64_t*)digest)[1] = h1;
|
||||
util_write64(digest + 0, h0);
|
||||
util_write64(digest + 8, h1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -502,6 +502,42 @@ static inline uint64_t util_swap64(uint64_t v)
|
|||
}
|
||||
#endif
|
||||
|
||||
static inline uint32_t util_read32(const void* ptr)
|
||||
{
|
||||
uint32_t v;
|
||||
memcpy(&v, ptr, sizeof(v));
|
||||
#if WORDS_BIGENDIAN
|
||||
v = util_swap32(v);
|
||||
#endif
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint64_t util_read64(const void* ptr)
|
||||
{
|
||||
uint64_t v;
|
||||
memcpy(&v, ptr, sizeof(v));
|
||||
#if WORDS_BIGENDIAN
|
||||
v = util_swap64(v);
|
||||
#endif
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline void util_write32(void* ptr, uint32_t v)
|
||||
{
|
||||
#if WORDS_BIGENDIAN
|
||||
v = util_swap32(v);
|
||||
#endif
|
||||
memcpy(ptr, &v, sizeof(v));
|
||||
}
|
||||
|
||||
static inline void util_write64(void* ptr, uint64_t v)
|
||||
{
|
||||
#if WORDS_BIGENDIAN
|
||||
v = util_swap64(v);
|
||||
#endif
|
||||
memcpy(ptr, &v, sizeof(v));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* hash */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue