2017-08-10 21:40:20 +02:00
|
|
|
#pragma once
|
2018-09-26 00:14:10 +02:00
|
|
|
|
|
|
|
#include "Utilities/types.h"
|
2017-08-10 21:40:20 +02:00
|
|
|
|
|
|
|
namespace rpcs3
|
|
|
|
{
|
|
|
|
template<typename T>
|
|
|
|
static size_t hash_base(T value)
|
|
|
|
{
|
|
|
|
return static_cast<size_t>(value);
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:41:45 +02:00
|
|
|
template<typename T, typename U>
|
|
|
|
static size_t hash_struct_base(const T& value)
|
2017-08-10 21:40:20 +02:00
|
|
|
{
|
|
|
|
// FNV 64-bit
|
|
|
|
size_t result = 14695981039346656037ull;
|
2018-07-24 22:41:45 +02:00
|
|
|
const U *bits = reinterpret_cast<const U*>(&value);
|
2017-08-10 21:40:20 +02:00
|
|
|
|
2018-07-24 22:41:45 +02:00
|
|
|
for (size_t n = 0; n < (sizeof(T) / sizeof(U)); ++n)
|
2017-08-10 21:40:20 +02:00
|
|
|
{
|
2018-07-24 22:41:45 +02:00
|
|
|
result ^= bits[n];
|
2017-08-10 21:40:20 +02:00
|
|
|
result *= 1099511628211ull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-07-24 22:41:45 +02:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static size_t hash_struct(const T& value)
|
|
|
|
{
|
|
|
|
static constexpr auto block_sz = sizeof(T);
|
|
|
|
|
2019-03-16 19:30:04 +01:00
|
|
|
if constexpr ((block_sz & 0x7) == 0)
|
2018-07-24 22:41:45 +02:00
|
|
|
{
|
|
|
|
return hash_struct_base<T, u64>(value);
|
|
|
|
}
|
|
|
|
|
2019-03-16 19:30:04 +01:00
|
|
|
if constexpr ((block_sz & 0x3) == 0)
|
2018-07-24 22:41:45 +02:00
|
|
|
{
|
|
|
|
return hash_struct_base<T, u32>(value);
|
|
|
|
}
|
|
|
|
|
2019-03-16 19:30:04 +01:00
|
|
|
if constexpr ((block_sz & 0x1) == 0)
|
2018-07-24 22:41:45 +02:00
|
|
|
{
|
|
|
|
return hash_struct_base<T, u16>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash_struct_base<T, u8>(value);
|
|
|
|
}
|
2018-09-26 00:14:10 +02:00
|
|
|
}
|