diff --git a/src/backend/core/Interpreter.cpp b/src/backend/core/Interpreter.cpp index 29eadd6..b9e9966 100644 --- a/src/backend/core/Interpreter.cpp +++ b/src/backend/core/Interpreter.cpp @@ -94,5 +94,18 @@ u32 Interpreter::Step() { return 1; } -u32 Interpreter::ExecuteCached() {} +u32 DivideAddr(u32 addr, u32& offset) { + offset = (addr & (MAX_LINES_PER_BLOCK - 1)) / 4; + return addr / MAX_LINES_PER_BLOCK; +} + +CachedLine* GetLine(CachedState& cachedState, u32 addr) { + u32 offset; + u32 page = DivideAddr(addr, offset); + return cachedState.blocks[page][offset].lines[0]; +} + +u32 Interpreter::ExecuteCached() { + +} } // namespace n64 diff --git a/src/backend/core/Interpreter.hpp b/src/backend/core/Interpreter.hpp index e73c915..9500e1b 100644 --- a/src/backend/core/Interpreter.hpp +++ b/src/backend/core/Interpreter.hpp @@ -6,6 +6,7 @@ namespace n64 { struct Core; static constexpr u32 MAX_INSTRUCTION_PER_LINE = 128; +static constexpr u32 MAX_LINES_PER_BLOCK = 1 << 12; struct CachedLine { std::array code; @@ -14,7 +15,15 @@ struct CachedLine { }; struct CachedBlock { - std::vector lines; + std::array lines; +}; + +using CachedBlocks = std::array, (u64(std::numeric_limits::max()) + 1) / MAX_LINES_PER_BLOCK>; + +struct CachedState { + CachedBlocks blocks; + CachedLine* lastLine = nullptr; + bool exception = false; }; struct Interpreter final { @@ -29,6 +38,9 @@ struct Interpreter final { private: friend struct Cop1; + + CachedState cachedState; + InstructionCache icache; DataCache dcache; Registers ®s;