mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-11-22 17:19:18 +01:00
Latte: Use better hashing algorithm for cache invalidation
Decreases chance of hash collisions while also being faster due to 4 channel vectorization
This commit is contained in:
parent
a640bd079c
commit
ecb7b77326
@ -734,20 +734,34 @@ private:
|
|||||||
|
|
||||||
static uint64 hashPage(uint8* mem)
|
static uint64 hashPage(uint8* mem)
|
||||||
{
|
{
|
||||||
// note - this algorithm is/was also baked into pageWriteStreamoutSignatures()
|
static const uint64 k0 = 0x55F23EAD;
|
||||||
uint64 h = 0;
|
static const uint64 k1 = 0x185FDC6D;
|
||||||
uint64* memU64 = (uint64*)mem;
|
static const uint64 k2 = 0xF7431F49;
|
||||||
for (uint32 i = 0; i < CACHE_PAGE_SIZE / 8; i++)
|
static const uint64 k3 = 0xA4C7AE9D;
|
||||||
{
|
|
||||||
//h = _rotr64(h, 7);
|
|
||||||
//h ^= *memU64;
|
|
||||||
//memU64++;
|
|
||||||
|
|
||||||
h = std::rotr<uint64>(h, 7);
|
cemu_assert_debug((CACHE_PAGE_SIZE % 32) == 0);
|
||||||
h += (*memU64 + (uint64)i);
|
const uint64* ptr = (const uint64*)mem;
|
||||||
memU64++;
|
const uint64* end = ptr + (CACHE_PAGE_SIZE / sizeof(uint64));
|
||||||
|
|
||||||
|
uint64 h0 = 0;
|
||||||
|
uint64 h1 = 0;
|
||||||
|
uint64 h2 = 0;
|
||||||
|
uint64 h3 = 0;
|
||||||
|
while (ptr < end)
|
||||||
|
{
|
||||||
|
h0 = std::rotr(h0, 7);
|
||||||
|
h1 = std::rotr(h1, 7);
|
||||||
|
h2 = std::rotr(h2, 7);
|
||||||
|
h3 = std::rotr(h3, 7);
|
||||||
|
|
||||||
|
h0 += ptr[0] * k0;
|
||||||
|
h1 += ptr[1] * k1;
|
||||||
|
h2 += ptr[2] * k2;
|
||||||
|
h3 += ptr[3] * k3;
|
||||||
|
ptr += 4;
|
||||||
}
|
}
|
||||||
return h;
|
|
||||||
|
return h0 + h1 + h2 + h3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// flag page as having streamout data, also write streamout signatures to page memory
|
// flag page as having streamout data, also write streamout signatures to page memory
|
||||||
|
Loading…
Reference in New Issue
Block a user