summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-11 17:53:25 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-11 17:57:13 +0200
commit5d1954365b9c1010372dfc020afb7ff7450b4e14 (patch)
tree9809411ea0468da74df62eb6c31849c1df020ea4 /compat
parentca4544f04cc67c296e58170e76203bc11519d988 (diff)
a
Diffstat (limited to 'compat')
-rw-r--r--compat/int-hash.cpp35
-rw-r--r--compat/int-hash.hpp4
2 files changed, 10 insertions, 29 deletions
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