Files
kaizen/src/backend/core/JITUtils.hpp
T
2026-05-28 17:57:46 +02:00

45 lines
1.1 KiB
C++

#pragma once
#include <Instruction.hpp>
#include <vector>
#include <array>
namespace n64 {
static constexpr u32 MAX_INSTR_PER_BLOCK = 128;
#define CACHE_GET_BLOCK(addr) (addr / (cachedState.MAX_LINES))
#define CACHE_GET_LINE(addr) ((addr & ((cachedState.MAX_LINES) - 1)) >> 2)
struct CachedLine {
std::array<Instruction, MAX_INSTR_PER_BLOCK> code = {};
u32 len = 0;
u32 cycles = 0;
} __attribute__((__packed__));
template <u32 lineAmount>
struct CachedBlock {
CachedBlock() { lines.resize(lineAmount); }
std::vector<CachedLine *> lines = {};
};
template <u32 blockBits, u64 addressSpace>
struct CachedState {
static constexpr u32 MAX_LINES = 1 << blockBits;
std::vector<CachedBlock<MAX_LINES / 4> *> blocks = {};
bool exception = false;
void EvictCachedBlock(u64 addr) { blocks[addr / MAX_LINES] = {}; }
void Reset() {
for (auto block : blocks) {
if (block)
for (auto line : block->lines)
delete line;
delete block;
}
blocks = {};
blocks.resize((addressSpace + 1) / MAX_LINES);
}
};
} // namespace n64