From fcc3c353fd250994dec73c4aa4bd66d976c910bb Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 3 Apr 2024 23:39:26 +0200 Subject: Separate gsl stuff, and use std-like int types --- deimos/core/hash.h | 80 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'deimos/core/hash.h') diff --git a/deimos/core/hash.h b/deimos/core/hash.h index e6e9cc8..f0eeafd 100644 --- a/deimos/core/hash.h +++ b/deimos/core/hash.h @@ -5,7 +5,7 @@ namespace deimos { -constexpr uint64 MurmurHash3_GetBlock64(const char* key, uint64 block) +constexpr uint64_t MurmurHash3_GetBlock64(const char* key, uint64_t block) { // NOLINTBEGIN key += block * 8; @@ -13,25 +13,25 @@ constexpr uint64 MurmurHash3_GetBlock64(const char* key, uint64 block) if consteval { return - (uint64)((uint8)key[0]) - | ((uint64)((uint8)key[1]) << 8) - | ((uint64)((uint8)key[2]) << 16) - | ((uint64)((uint8)key[3]) << 24) - | ((uint64)((uint8)key[4]) << 32) - | ((uint64)((uint8)key[5]) << 40) - | ((uint64)((uint8)key[6]) << 48) - | ((uint64)((uint8)key[7]) << 56); + (uint64_t)((uint8_t)key[0]) + | ((uint64_t)((uint8_t)key[1]) << 8) + | ((uint64_t)((uint8_t)key[2]) << 16) + | ((uint64_t)((uint8_t)key[3]) << 24) + | ((uint64_t)((uint8_t)key[4]) << 32) + | ((uint64_t)((uint8_t)key[5]) << 40) + | ((uint64_t)((uint8_t)key[6]) << 48) + | ((uint64_t)((uint8_t)key[7]) << 56); } else { - uint64 value{}; + uint64_t value{}; __builtin_memcpy(&value, key, 8); return value; } // NOLINTEND } -constexpr uint64 MurmurHash3_Fmix64(uint64 k) +constexpr uint64_t MurmurHash3_Fmix64(uint64_t k) { k ^= k >> 33U; k *= 0xff51afd7ed558ccdULL; @@ -41,27 +41,27 @@ constexpr uint64 MurmurHash3_Fmix64(uint64 k) return k; } -constexpr uint128 MurmurHash3_x64_128(const char* key, uint64 len) +constexpr uint128_t MurmurHash3_x64_128(const char* key, uint64_t len) { if consteval { return { 12, 12 }; } // NOLINTBEGIN - const uint64 nblocks = len / 16; + const uint64_t nblocks = len / 16; - const int64 seed = 0; - uint64 h1 = seed; - uint64 h2 = seed; + const uint64_t seed = 0; + uint64_t h1 = seed; + uint64_t h2 = seed; - const uint64 c1 = 0x87c37b91114253d5ULL; - const uint64 c2 = 0x4cf5ad432745937fULL; + const uint64_t c1 = 0x87c37b91114253d5ULL; + const uint64_t c2 = 0x4cf5ad432745937fULL; //---------- // body - for(uint64 i = 0; i < nblocks; i++) + for(uint64_t i = 0; i < nblocks; i++) { - uint64 k1 = MurmurHash3_GetBlock64(key, i * 2 + 0); - uint64 k2 = MurmurHash3_GetBlock64(key, i * 2 + 1); + uint64_t k1 = MurmurHash3_GetBlock64(key, i * 2 + 0); + uint64_t k2 = MurmurHash3_GetBlock64(key, i * 2 + 1); k1 *= c1; k1 = _rotl64(k1, 31); k1 *= c2; h1 ^= k1; h1 = _rotl64(h1, 27); h1 += h2; h1 = h1*5+0x52dce729; @@ -74,28 +74,28 @@ constexpr uint128 MurmurHash3_x64_128(const char* key, uint64 len) const char* tail = key + nblocks * 16; - uint64 k1 = 0; - uint64 k2 = 0; + uint64_t k1 = 0; + uint64_t k2 = 0; switch (len & 15ULL) { - case 15: k2 ^= ((uint64)(uint8)tail[14]) << 48U; [[fallthrough]]; - case 14: k2 ^= ((uint64)(uint8)tail[13]) << 40U; [[fallthrough]]; - case 13: k2 ^= ((uint64)(uint8)tail[12]) << 32U; [[fallthrough]]; - case 12: k2 ^= ((uint64)(uint8)tail[11]) << 24U; [[fallthrough]]; - case 11: k2 ^= ((uint64)(uint8)tail[10]) << 16U; [[fallthrough]]; - case 10: k2 ^= ((uint64)(uint8)tail[ 9]) << 8U; [[fallthrough]]; - case 9: k2 ^= ((uint64)(uint8)tail[ 8]) << 0U; + case 15: k2 ^= ((uint64_t)(uint8_t)tail[14]) << 48U; [[fallthrough]]; + case 14: k2 ^= ((uint64_t)(uint8_t)tail[13]) << 40U; [[fallthrough]]; + case 13: k2 ^= ((uint64_t)(uint8_t)tail[12]) << 32U; [[fallthrough]]; + case 12: k2 ^= ((uint64_t)(uint8_t)tail[11]) << 24U; [[fallthrough]]; + case 11: k2 ^= ((uint64_t)(uint8_t)tail[10]) << 16U; [[fallthrough]]; + case 10: k2 ^= ((uint64_t)(uint8_t)tail[ 9]) << 8U; [[fallthrough]]; + case 9: k2 ^= ((uint64_t)(uint8_t)tail[ 8]) << 0U; k2 *= c2; k2 = _rotl64(k2,33); k2 *= c1; h2 ^= k2; [[fallthrough]]; - case 8: k1 ^= ((uint64)(uint8)tail[ 7]) << 56U; [[fallthrough]]; - case 7: k1 ^= ((uint64)(uint8)tail[ 6]) << 48U; [[fallthrough]]; - case 6: k1 ^= ((uint64)(uint8)tail[ 5]) << 40U; [[fallthrough]]; - case 5: k1 ^= ((uint64)(uint8)tail[ 4]) << 32U; [[fallthrough]]; - case 4: k1 ^= ((uint64)(uint8)tail[ 3]) << 24U; [[fallthrough]]; - case 3: k1 ^= ((uint64)(uint8)tail[ 2]) << 16U; [[fallthrough]]; - case 2: k1 ^= ((uint64)(uint8)tail[ 1]) << 8U; [[fallthrough]]; - case 1: k1 ^= ((uint64)(uint8)tail[ 0]) << 0U; + case 8: k1 ^= ((uint64_t)(uint8_t)tail[ 7]) << 56U; [[fallthrough]]; + case 7: k1 ^= ((uint64_t)(uint8_t)tail[ 6]) << 48U; [[fallthrough]]; + case 6: k1 ^= ((uint64_t)(uint8_t)tail[ 5]) << 40U; [[fallthrough]]; + case 5: k1 ^= ((uint64_t)(uint8_t)tail[ 4]) << 32U; [[fallthrough]]; + case 4: k1 ^= ((uint64_t)(uint8_t)tail[ 3]) << 24U; [[fallthrough]]; + case 3: k1 ^= ((uint64_t)(uint8_t)tail[ 2]) << 16U; [[fallthrough]]; + case 2: k1 ^= ((uint64_t)(uint8_t)tail[ 1]) << 8U; [[fallthrough]]; + case 1: k1 ^= ((uint64_t)(uint8_t)tail[ 0]) << 0U; k1 *= c1; k1 = _rotl64(k1,31); k1 *= c2; h1 ^= k1; }; @@ -114,10 +114,10 @@ constexpr uint128 MurmurHash3_x64_128(const char* key, uint64 len) h2 += h1; // NOLINTEND - return uint128{h1, h2}; + return uint128_t{h1, h2}; } -constexpr uint128 MurmurHash3_x64_128(gsl::czstring str) +constexpr uint128_t MurmurHash3_x64_128(gsl::czstring str) { return MurmurHash3_x64_128(str, __builtin_strlen(str)); } -- cgit