From 5d1954365b9c1010372dfc020afb7ff7450b4e14 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 11 Oct 2023 17:53:25 +0200 Subject: a --- compat/int-hash.cpp | 35 ++++++++--------------------------- compat/int-hash.hpp | 4 ++-- 2 files changed, 10 insertions(+), 29 deletions(-) (limited to 'compat') diff --git a/compat/int-hash.cpp b/compat/int-hash.cpp index 79b5dfad..f9ae19c1 100644 --- a/compat/int-hash.cpp +++ b/compat/int-hash.cpp @@ -35,41 +35,22 @@ fm_UNROLL_8 } // namespace -#define fnvhash_64_ROUND() do { hash *= 0x01000193u; hash ^= (uint8_t)*str++; } while(false) - -uint64_t fnvhash_64(const void* str_, size_t size) +uint64_t fnvhash_32(const void* buf, size_t size) { - const auto *str = (const char*)str_; + const auto *str = (const char*)buf, *const end = str + size; uint32_t hash = 0x811c9dc5u; - size_t full = size / 8; - for (size_t i = 0; i < full; i++) - { - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - fnvhash_64_ROUND(); - } - switch (size & 7u) +fm_UNROLL_8 + for (; str != end; ++str) { - case 7: fnvhash_64_ROUND(); [[fallthrough]]; - case 6: fnvhash_64_ROUND(); [[fallthrough]]; - case 5: fnvhash_64_ROUND(); [[fallthrough]]; - case 4: fnvhash_64_ROUND(); [[fallthrough]]; - case 3: fnvhash_64_ROUND(); [[fallthrough]]; - case 2: fnvhash_64_ROUND(); [[fallthrough]]; - case 1: fnvhash_64_ROUND(); [[fallthrough]]; - case 0: break; + hash *= 0x01000193u; + hash ^= (uint8_t)*str; } return hash; } -uint64_t fnvhash_32(const void* str_, size_t size) +uint64_t fnvhash_64(const void* buf, size_t size) { - const auto *str = (const char*)str_, *end = str + size; + const auto *str = (const char*)buf, *const end = str + size; uint64_t hash = 0xcbf29ce484222325u; fm_UNROLL_4 for (; str != end; ++str) diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp index 6a6cbcd4..86fc6a45 100644 --- a/compat/int-hash.hpp +++ b/compat/int-hash.hpp @@ -5,7 +5,7 @@ namespace floormat { size_t int_hash(uint32_t x) noexcept; size_t int_hash(uint64_t x) noexcept; -uint64_t fnvhash_64(const void* str, size_t size); -uint64_t fnvhash_32(const void* str, size_t size); +uint64_t fnvhash_64(const void* buf, size_t size); +uint64_t fnvhash_32(const void* buf, size_t size); } // namespace floormat -- cgit v1.2.3