Skip to content

Instantly share code, notes, and snippets.

@FioraAeterna
Created December 27, 2014 04:13
Show Gist options
  • Select an option

  • Save FioraAeterna/0f36e1c3d3252bc92e58 to your computer and use it in GitHub Desktop.

Select an option

Save FioraAeterna/0f36e1c3d3252bc92e58 to your computer and use it in GitHub Desktop.
icache hashing
static inline u64 crccode(u32* src, int insts)
{
int i = 0;
u64 res = 0;
if (insts >= 4)
{
u64 val[2] = { *(u64*)&src[0], *(u64*)&src[2] };
src += 4;
insts -= 4;
while (insts >= 4)
{
val[0] = _mm_crc32_u64(val[0], *(u64*)&src[i+0]);
val[1] = _mm_crc32_u64(val[1], *(u64*)&src[i+2]);
src += 4;
insts -= 4;
}
res = _mm_crc32_u64(val[0], val[1]);
}
for (int i = 0; i < insts; i++)
res = _mm_crc32_u64(res, src[i]);
return res;
}
bool check_cache(JitBlock *b)
{
u32 address = b->originalAddress;
u8* memaddress = Memory::base + address;
int size = b->originalSize;
u64 crc = crccode((u32*)memaddress, size);
if (crc != b->crc)
{
JitInterface::InvalidateICache(address, size*4, false);
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment