1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

UserspaceEmulator: Add a very simple instruction fetch cache

To avoid MMU region lookup on every single instruction fetch, we now
cache a raw pointer to the current instruction. This gets automatically
invalidated when we jump somewhere, but as long as we're executing
sequentially, instruction fetches will hit the cache and bypass all
the region lookup stuff.

This is about a ~2x speedup. :^)
This commit is contained in:
Andreas Kling 2020-07-13 20:14:14 +02:00
parent c8d3f8cdeb
commit 8656835935
5 changed files with 44 additions and 4 deletions

View file

@ -56,7 +56,12 @@ public:
void dump() const;
u32 eip() const { return m_eip; }
void set_eip(u32 eip) { m_eip = eip; }
void set_eip(u32 eip)
{
m_eip = eip;
m_cached_code_ptr = nullptr;
m_cached_code_end = nullptr;
}
struct Flags {
enum Flag {
@ -792,6 +797,8 @@ private:
template<bool check_zf, typename Callback>
void do_once_or_repeat(const X86::Instruction& insn, Callback);
void update_code_cache();
private:
Emulator& m_emulator;
@ -800,6 +807,9 @@ private:
u32 m_eflags { 0 };
u32 m_eip { 0 };
const u8* m_cached_code_ptr { nullptr };
const u8* m_cached_code_end { nullptr };
};
}