summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/zix/digest.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/zix/digest.c b/src/zix/digest.c
index 2ac1715..03a1210 100644
--- a/src/zix/digest.c
+++ b/src/zix/digest.c
@@ -38,6 +38,7 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
{
const uint8_t* str = (const uint8_t*)buf;
+#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);
str += sizeof(uint64_t);
@@ -46,6 +47,12 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
hash = _mm_crc32_u32(hash, *(const uint32_t*)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);
+ str += sizeof(uint32_t);
+ }
+#endif
if (len & sizeof(uint16_t)) {
hash = _mm_crc32_u16(hash, *(const uint16_t*)str);
str += sizeof(uint16_t);
@@ -63,6 +70,7 @@ zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len)
assert((uintptr_t)buf % sizeof(uint64_t) == 0);
assert(len % sizeof(uint64_t) == 0);
+#ifdef __x86_64__
const uint64_t* ptr = (const uint64_t*)buf;
for (size_t i = 0; i < (len / sizeof(uint64_t)); ++i) {
@@ -71,12 +79,22 @@ zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len)
}
return hash;
+#else
+ const uint32_t* ptr = (const uint32_t*)buf;
+
+ for (size_t i = 0; i < (len / sizeof(uint32_t)); ++i) {
+ hash = _mm_crc32_u32(hash, *ptr);
+ ++ptr;
+ }
+
+ return hash;
+#endif
}
uint32_t
zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
{
-#if UINTPTR_MAX == UINT64_MAX
+#ifdef __x86_64__
return (uint32_t)_mm_crc32_u64(hash, (uintptr_t)ptr);
#else
return _mm_crc32_u32(hash, (uintptr_t)ptr);