summaryrefslogtreecommitdiffstats
path: root/zix/digest.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-31 15:15:05 +0100
committerDavid Robillard <d@drobilla.net>2020-12-31 15:21:29 +0100
commit741c3349b09c8774fcd013e3bdd7d9e7f6b470ce (patch)
treea941f6567b85255570e5492f3c66a842704ba9f7 /zix/digest.c
parent841c766d86dc35ab37c4fef8ec866d06c41bc383 (diff)
downloadzix-741c3349b09c8774fcd013e3bdd7d9e7f6b470ce.tar.gz
zix-741c3349b09c8774fcd013e3bdd7d9e7f6b470ce.tar.bz2
zix-741c3349b09c8774fcd013e3bdd7d9e7f6b470ce.zip
Format all code with clang-format
Diffstat (limited to 'zix/digest.c')
-rw-r--r--zix/digest.c120
1 files changed, 60 insertions, 60 deletions
diff --git a/zix/digest.c b/zix/digest.c
index 03a1210..941b05c 100644
--- a/zix/digest.c
+++ b/zix/digest.c
@@ -17,7 +17,7 @@
#include "zix/digest.h"
#ifdef __SSE4_2__
-# include <smmintrin.h>
+# include <smmintrin.h>
#endif
#include <assert.h>
@@ -30,75 +30,75 @@
uint32_t
zix_digest_start(void)
{
- return 1;
+ return 1;
}
uint32_t
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);
- }
- if (len & sizeof(uint32_t)) {
- 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);
- }
- if (len & sizeof(uint8_t)) {
- hash = _mm_crc32_u8(hash, *(const uint8_t*)str);
- }
-
- return hash;
+ 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);
+ }
+ if (len & sizeof(uint32_t)) {
+ 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);
+ }
+ if (len & sizeof(uint8_t)) {
+ hash = _mm_crc32_u8(hash, *(const uint8_t*)str);
+ }
+
+ return hash;
}
uint32_t
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);
+ 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;
+# ifdef __x86_64__
+ const uint64_t* ptr = (const uint64_t*)buf;
- for (size_t i = 0; i < (len / sizeof(uint64_t)); ++i) {
- hash = (uint32_t)_mm_crc32_u64(hash, *ptr);
- ++ptr;
- }
+ for (size_t i = 0; i < (len / sizeof(uint64_t)); ++i) {
+ hash = (uint32_t)_mm_crc32_u64(hash, *ptr);
+ ++ptr;
+ }
- return hash;
-#else
- const uint32_t* ptr = (const uint32_t*)buf;
+ 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;
- }
+ for (size_t i = 0; i < (len / sizeof(uint32_t)); ++i) {
+ hash = _mm_crc32_u32(hash, *ptr);
+ ++ptr;
+ }
- return hash;
-#endif
+ return hash;
+# endif
}
uint32_t
zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
{
-#ifdef __x86_64__
- return (uint32_t)_mm_crc32_u64(hash, (uintptr_t)ptr);
-#else
- return _mm_crc32_u32(hash, (uintptr_t)ptr);
-#endif
+# ifdef __x86_64__
+ return (uint32_t)_mm_crc32_u64(hash, (uintptr_t)ptr);
+# else
+ return _mm_crc32_u32(hash, (uintptr_t)ptr);
+# endif
}
#else
@@ -108,34 +108,34 @@ zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
uint32_t
zix_digest_start(void)
{
- return 5381;
+ return 5381;
}
uint32_t
zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
{
- const uint8_t* str = (const uint8_t*)buf;
+ const uint8_t* str = (const uint8_t*)buf;
- for (size_t i = 0; i < len; ++i) {
- hash = (hash << 5u) + hash + str[i];
- }
+ for (size_t i = 0; i < len; ++i) {
+ hash = (hash << 5u) + hash + str[i];
+ }
- return hash;
+ return hash;
}
uint32_t
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);
+ assert((uintptr_t)buf % sizeof(uint64_t) == 0);
+ assert(len % sizeof(uint64_t) == 0);
- return zix_digest_add(hash, buf, len);
+ return zix_digest_add(hash, buf, len);
}
uint32_t
zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
{
- return zix_digest_add(hash, &ptr, sizeof(ptr));
+ return zix_digest_add(hash, &ptr, sizeof(ptr));
}
#endif