summaryrefslogtreecommitdiffstats
path: root/src/digest.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-09-10 20:11:41 -0400
committerDavid Robillard <d@drobilla.net>2021-09-10 20:54:28 -0400
commit0f06d8ae30119e10ffb2b7b5ec5e6b51c624cd1d (patch)
treea431d0b291dd8a652712ab2c4c5c5eca9be0b71b /src/digest.c
parent06443ecb437eebcf3373b1034ca5ff84ebe212df (diff)
downloadzix-0f06d8ae30119e10ffb2b7b5ec5e6b51c624cd1d.tar.gz
zix-0f06d8ae30119e10ffb2b7b5ec5e6b51c624cd1d.tar.bz2
zix-0f06d8ae30119e10ffb2b7b5ec5e6b51c624cd1d.zip
Fix cast alignment warnings in SSE4.2 digest code
Diffstat (limited to 'src/digest.c')
-rw-r--r--src/digest.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/digest.c b/src/digest.c
index 47d27b9..c14a3f5 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -33,6 +33,30 @@ zix_digest_start(void)
return 1;
}
+static inline uint64_t
+load64(const void* const mem)
+{
+ uint64_t r = 0u;
+ memcpy(&r, mem, sizeof(r));
+ return r;
+}
+
+static inline uint32_t
+load32(const void* const mem)
+{
+ uint32_t r = 0u;
+ memcpy(&r, mem, sizeof(r));
+ return r;
+}
+
+static inline uint16_t
+load16(const void* const mem)
+{
+ uint16_t r = 0u;
+ memcpy(&r, mem, sizeof(r));
+ return r;
+}
+
uint32_t
zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
{
@@ -40,25 +64,25 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
# ifdef __x86_64__
for (size_t i = 0; i < (len / sizeof(uint64_t)); ++i) {
- hash = (uint32_t)_mm_crc32_u64(hash, *(const uint64_t*)str);
+ hash = (uint32_t)_mm_crc32_u64(hash, load64(str));
str += sizeof(uint64_t);
}
if (len & sizeof(uint32_t)) {
- hash = _mm_crc32_u32(hash, *(const uint32_t*)str);
+ hash = _mm_crc32_u32(hash, load32(str));
str += sizeof(uint32_t);
}
# else
for (size_t i = 0; i < (len / sizeof(uint32_t)); ++i) {
- hash = _mm_crc32_u32(hash, *(const uint32_t*)str);
+ hash = _mm_crc32_u32(hash, load32(str));
str += sizeof(uint32_t);
}
# endif
if (len & sizeof(uint16_t)) {
- hash = _mm_crc32_u16(hash, *(const uint16_t*)str);
+ hash = _mm_crc32_u16(hash, load16(str));
str += sizeof(uint16_t);
}
if (len & sizeof(uint8_t)) {
- hash = _mm_crc32_u8(hash, *(const uint8_t*)str);
+ hash = _mm_crc32_u8(hash, *str);
}
return hash;