New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache very common instructions #113
Comments
Concept idea:Add an extra layer above the ZydisDecoderDecodeBufferCached(ZydisDecoder decoder, ...,
const ZydisCacheTable* cache, ZydisDecodedInstruction** instruction)
// The `instruction` parameter could be used as in- and output: A pointer to the cached
// instruction is returned, if it was found in the cache ...
// ... or directly fill the passed struct, if the instruction was not found in the cache.
ZydisDecodedInstruction instruction_data;
ZydisDecodedInstruction* instruction = &instruction_data;
ZydisDecoderDecodeBufferCached(..., &instruction);
// E.g.:
ZyanStatus ZydisDecoderDecodeBufferCached(..., ZydisDecodedInstruction** instruction)
{
// ...
if (found_in_cache)
{
*instruction = &cache[index];
return ZYAN_STATUS_TRUE; // indicate, that the instruction was cached
} else
{
const ZyanStatus status = ZydisDecoderDecodeBuffer(..., *instruction);
ZYAN_CHECK(status);
return ZYAN_STATUS_FALSE; // indicate, that the instruction was not cached
}
} Make sure to add good documentation about the in/out parameter and warn the user to not override data in a cached instruction (could be indicated by the return code). Add an initializer function: ZydisDecoderInitializeCache(ZydisDecoder decoder, ZydisCacheTable* cache) Define the typedef struct ZydisCacheTable_
{
ZyanI8 index[2][256]; // <- up to 2-byte opcodes for now; easy to extend
ZydisDecodedInstruction instructions[n];
} ZydisCacheTable; |
With a detached caching layer, we can just make the |
It might be worth a try to cache the ~10 most common instructions in the decoder for improved performance. I did a very hacky quick test and determined that caching
CC
and00 00
alone results in a ~10% performance boost.The text was updated successfully, but these errors were encountered: