summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-30 15:09:26 +0100
committerDavid Robillard <d@drobilla.net>2020-11-30 15:09:26 +0100
commitd77a9f9532fe4412795b433208f80d96f99a2ff1 (patch)
treec5056ba92699c7374438b6a10f931cb0d2996669 /src
parent09aee4137b742819eb1ebfe4390d8809393e32ab (diff)
downloadsord-d77a9f9532fe4412795b433208f80d96f99a2ff1.tar.gz
sord-d77a9f9532fe4412795b433208f80d96f99a2ff1.tar.bz2
sord-d77a9f9532fe4412795b433208f80d96f99a2ff1.zip
Fix build on x32 with SSE 4.2
Diffstat (limited to 'src')
-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);