[*] The runtime variant of Fnv1a was completely FUCKED
This commit is contained in:
parent
9e527bbe3c
commit
91a83c2353
@ -142,7 +142,7 @@ inline AuUInt32 AuFnv1a32Runtime(const void *base, AuUInt length) noexcept
|
||||
AuUInt i {};
|
||||
for (; i < length; i++)
|
||||
{
|
||||
result ^= AuUInt32(AuReadU8(base, i)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32(AuReadU8(base, i))) * AuUInt64(kFnv1MagicPrime32);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -155,7 +155,7 @@ inline AuUInt64 AuFnv1a64Runtime(const void *base, AuUInt length) noexcept
|
||||
AuUInt i {};
|
||||
for (; i < length; i++)
|
||||
{
|
||||
result ^= AuUInt64(AuReadU8(base, i)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64(AuReadU8(base, i))) * AuUInt64(kFnv1MagicPrime64);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -168,6 +168,131 @@ inline auto AuFnv1aRuntime(const void *base, AuUInt length) noexcept
|
||||
AuFnv1a64Runtime(base, length);
|
||||
}
|
||||
|
||||
template <AuUInt uCount>
|
||||
inline AuUInt64 AuFnv1a64Runtime(const void *base) noexcept
|
||||
{
|
||||
AuUInt64 result { kFnv1MagicVal64 };
|
||||
|
||||
AuUInt i {};
|
||||
for (; i < uCount; i++)
|
||||
{
|
||||
result = (result ^ AuUInt64(AuReadU8(base, i))) * AuUInt64(kFnv1MagicPrime64);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template <AuUInt uCount>
|
||||
inline AuUInt32 AuFnv1a32Runtime(const void *base) noexcept
|
||||
{
|
||||
AuUInt32 result { kFnv1MagicVal32 };
|
||||
|
||||
AuUInt i {};
|
||||
for (; i < uCount; i++)
|
||||
{
|
||||
result = (result ^ AuUInt32(AuReadU8(base, i))) * AuUInt32(kFnv1MagicPrime32);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined(AU_CPU_ENDIAN_LITTLE)
|
||||
|
||||
template <>
|
||||
inline AuUInt32 AuFnv1a32Runtime<2>(const void *base) noexcept
|
||||
{
|
||||
AuUInt32 result { kFnv1MagicVal32 };
|
||||
|
||||
auto uWord16 = AuReadU16(base, 0);
|
||||
result = (result ^ AuUInt32((uWord16 & 0xFF) >> 0)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord16 & 0xFF00) >> 8)) * AuUInt32(kFnv1MagicPrime32);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline AuUInt32 AuFnv1a32Runtime<4>(const void *base) noexcept
|
||||
{
|
||||
AuUInt32 result { kFnv1MagicVal32 };
|
||||
|
||||
auto uWord32 = AuReadU32(base, 0);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF) >> 0)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF00) >> 8)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF0000) >> 16)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF000000) >> 24)) * AuUInt32(kFnv1MagicPrime32);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline AuUInt32 AuFnv1a32Runtime<8>(const void *base) noexcept
|
||||
{
|
||||
AuUInt32 result { kFnv1MagicVal32 };
|
||||
|
||||
auto uWord32 = AuReadU32(base, 0);
|
||||
auto uWord32Hi = AuReadU32(base, 4);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF) >> 0)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF00) >> 8)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF0000) >> 16)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32 & 0xFF000000) >> 24)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32Hi & 0xFF) >> 0)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32Hi & 0xFF00) >> 8)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32Hi & 0xFF0000) >> 16)) * AuUInt32(kFnv1MagicPrime32);
|
||||
result = (result ^ AuUInt32((uWord32Hi & 0xFF000000) >> 24)) * AuUInt32(kFnv1MagicPrime32);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline AuUInt64 AuFnv1a64Runtime<2>(const void *base) noexcept
|
||||
{
|
||||
AuUInt64 result { kFnv1MagicVal64 };
|
||||
|
||||
auto uWord16 = AuReadU16(base, 0);
|
||||
result = (result ^ AuUInt64((uWord16 & 0xFF) >> 0)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord16 & 0xFF00) >> 8)) * AuUInt64(kFnv1MagicPrime64);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline AuUInt64 AuFnv1a64Runtime<4>(const void *base) noexcept
|
||||
{
|
||||
AuUInt64 result { kFnv1MagicVal64 };
|
||||
|
||||
auto uWord64 = AuReadU32(base, 0);
|
||||
result = (result ^ AuUInt64((uWord64 & 0xFF) >> 0)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord64 & 0xFF00) >> 8)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord64 & 0xFF0000) >> 16)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord64 & 0xFF000000) >> 24)) * AuUInt64(kFnv1MagicPrime64);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline AuUInt64 AuFnv1a64Runtime<8>(const void *base) noexcept
|
||||
{
|
||||
AuUInt64 result { kFnv1MagicVal64 };
|
||||
|
||||
auto uWord32 = AuReadU32(base, 0);
|
||||
auto uWord32Hi = AuReadU32(base, 4);
|
||||
result = (result ^ AuUInt64((uWord32 & 0xFF) >> 0)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32 & 0xFF00) >> 8)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32 & 0xFF0000) >> 16)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32 & 0xFF000000) >> 24)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32Hi & 0xFF) >> 0)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32Hi & 0xFF00) >> 8)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32Hi & 0xFF0000) >> 16)) * AuUInt64(kFnv1MagicPrime64);
|
||||
result = (result ^ AuUInt64((uWord32Hi & 0xFF000000) >> 24)) * AuUInt64(kFnv1MagicPrime64);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <AuUInt uCount>
|
||||
inline auto AuFnv1aRuntime(const void *base) noexcept
|
||||
{
|
||||
return _AU_FNV1_32 ?
|
||||
AuFnv1a32Runtime<uCount>(base) :
|
||||
AuFnv1a64Runtime<uCount>(base);
|
||||
}
|
||||
|
||||
#undef _AU_FNV1_32
|
||||
|
||||
#if defined(_AU_HASH_RETARD_COMPILER)
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#define _AU_HASH_UTILS_HAS_STD
|
||||
|
||||
#if defined(AURORA_COMPILER_CLANG) && !defined(AURORA_BUG_DOES_CLANG_SUPPORT_64_BIT_CONSTEXPR_YET)
|
||||
#if 1 || defined(AURORA_COMPILER_CLANG) && !defined(AURORA_BUG_DOES_CLANG_SUPPORT_64_BIT_CONSTEXPR_YET)
|
||||
#define _AU_HASH_RETARD_COMPILER
|
||||
#define _AH_HAS_RETARD_CONSTEXPR
|
||||
#else
|
||||
@ -96,7 +96,7 @@ namespace AuHash
|
||||
#if defined(_AU_HASH_RETARD_COMPILER)
|
||||
return AuFnv1aRuntime(&key, sizeof(key));
|
||||
#else
|
||||
return AuFnv1aType<AuUInt32>(key);
|
||||
return AuFnv1a64Runtime<sizeof(AuUInt32)>(&key);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ namespace AuHash
|
||||
#if defined(_AU_HASH_RETARD_COMPILER)
|
||||
return AuFnv1aRuntime(&key, sizeof(key));
|
||||
#else
|
||||
return AuFnv1aType<AuUInt64>(key);
|
||||
return AuFnv1a64Runtime<sizeof(AuUInt64)>(&key);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -117,7 +117,7 @@ namespace AuHash
|
||||
{ \
|
||||
_AH_HAS_RETARD_CONSTEXPR AuUInt operator ()(const type b) const \
|
||||
{ \
|
||||
return AuFnv1aRuntime(&b, sizeof(b)); \
|
||||
return AuFnv1aRuntime<sizeof(b)>(&b); \
|
||||
} \
|
||||
};
|
||||
#else
|
||||
@ -127,7 +127,7 @@ namespace AuHash
|
||||
{ \
|
||||
_AH_HAS_RETARD_CONSTEXPR AuUInt operator ()(const type b) const \
|
||||
{ \
|
||||
return AuFnv1aType<type>(b); \
|
||||
return AuFnv1aRuntime<sizeof(b)>(&b); \
|
||||
} \
|
||||
};
|
||||
#endif
|
||||
@ -184,6 +184,7 @@ namespace AuHash
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
_HASH_INT32BIT(bool);
|
||||
_HASH_INT32BIT(char);
|
||||
_HASH_INT32BIT(signed char);
|
||||
@ -200,6 +201,24 @@ namespace AuHash
|
||||
_HASH_INT64BIT(long long);
|
||||
_HASH_INT64BIT(unsigned long);
|
||||
_HASH_INT64BIT(unsigned long long);
|
||||
#else
|
||||
_HASH_INT(bool);
|
||||
_HASH_INT(char);
|
||||
_HASH_INT(signed char);
|
||||
_HASH_INT(unsigned char);
|
||||
_HASH_INT(char8_t);
|
||||
_HASH_INT(char16_t);
|
||||
_HASH_INT(char32_t);
|
||||
_HASH_INT(wchar_t);
|
||||
_HASH_INT(short);
|
||||
_HASH_INT(unsigned short);
|
||||
_HASH_INT(int);
|
||||
_HASH_INT(unsigned int);
|
||||
_HASH_INT(long); // I know, I don't care.
|
||||
_HASH_INT(long long);
|
||||
_HASH_INT(unsigned long);
|
||||
_HASH_INT(unsigned long long);
|
||||
#endif
|
||||
_HASH_INT(float);
|
||||
_HASH_INT(double);
|
||||
_HASH_INT(long double);
|
||||
@ -409,9 +428,9 @@ struct AuEnableHashCodeOnData
|
||||
AuUInt HashCode() const
|
||||
{
|
||||
#if defined(AURORA_IS_32BIT)
|
||||
return AuFnv1a32Runtime(AuStaticCast<AuAddConst_t<T>>(this), sizeof(T));
|
||||
return AuFnv1a64Runtime<sizeof(T)>(AuStaticCast<AuAddConst_t<T>>(this));
|
||||
#else
|
||||
return AuFnv1a64Runtime(AuStaticCast<AuAddConst_t<T>>(this), sizeof(T));
|
||||
return AuFnv1a64Runtime<sizeof(T)>(AuStaticCast<AuAddConst_t<T>>(this));
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user