Created
December 27, 2014 04:13
-
-
Save FioraAeterna/0f36e1c3d3252bc92e58 to your computer and use it in GitHub Desktop.
icache hashing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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