diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-09 06:20:09 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-09 09:38:58 +0200 |
| commit | 83e6715e39f9496b3043df70b1545e0a6284619f (patch) | |
| tree | 5fdc4fe8cfc5a3eeead9b65233240ac07d349647 /hash/xxhash.cpp | |
| parent | 29cd4d4e3bbf519a95763394801caeb43c7b5629 (diff) | |
hash: add library with multiple hash implementations
Diffstat (limited to 'hash/xxhash.cpp')
| -rw-r--r-- | hash/xxhash.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/hash/xxhash.cpp b/hash/xxhash.cpp new file mode 100644 index 00000000..c720465e --- /dev/null +++ b/hash/xxhash.cpp @@ -0,0 +1,39 @@ +#include "hash-impl.hpp" +#include "compat/map.hpp" +#include "compat/iota.hpp" +#include <bit> + +#ifdef __GNUG__ +//#pragma GCC diagnostic ignored "-Wdisabled-macro-expansion" +//#pragma GCC diagnostic ignored "-Wused-but-marked-unused" +#include "xxhash.inl" +#endif + +namespace floormat::xxHash { + +namespace { + +constexpr inline auto seed = std::bit_cast<uint64_t>(iota_array<uint8_t, 8>); + +CORRADE_ALWAYS_INLINE size_t do_xxhash(const void* __restrict buf, size_t size) noexcept +{ +#ifdef __AVX2__ + return XXH3_64bits(buf, size); +#error "foo avx" +#elif __SSE2__ + return (size_t)XXH3_64bits(buf, size); +#else + if constexpr(sizeof nullptr > 4) + return XXH364(buf, size); + else + return XXH32(buf, size); +#endif +} + +} // namespace + +size_t hash_buf(const void* __restrict buf, size_t size) noexcept { return do_xxhash(buf, size); } +size_t hash_int(uint32_t x) noexcept { return do_xxhash(&x, sizeof x); } +size_t hash_int(uint64_t x) noexcept { return do_xxhash(&x, sizeof x); } + +} // namespace floormat::xxHash |
