2019-11-19 10:30:04 +00:00
|
|
|
#pragma once
|
|
|
|
#include "common/bitfield.h"
|
|
|
|
#include "cpu_types.h"
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class JitCodeBuffer;
|
|
|
|
|
|
|
|
class Bus;
|
2019-11-19 14:15:14 +00:00
|
|
|
class System;
|
2019-11-19 10:30:04 +00:00
|
|
|
|
|
|
|
namespace CPU {
|
|
|
|
class Core;
|
|
|
|
|
|
|
|
namespace Recompiler {
|
|
|
|
class ASMFunctions;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CodeCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CodeCache();
|
|
|
|
~CodeCache();
|
|
|
|
|
2019-11-19 14:15:14 +00:00
|
|
|
void Initialize(System* system, Core* core, Bus* bus);
|
2019-11-19 10:30:04 +00:00
|
|
|
void Reset();
|
|
|
|
void Execute();
|
|
|
|
|
|
|
|
/// Flushes all blocks which are in the range of the specified code page.
|
|
|
|
void FlushBlocksWithPageIndex(u32 page_index);
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BlockMap = std::unordered_map<u32, CodeBlock*>;
|
|
|
|
|
2019-11-21 13:33:58 +00:00
|
|
|
void LogCurrentState();
|
|
|
|
|
2019-11-19 15:19:03 +00:00
|
|
|
CodeBlockKey GetNextBlockKey() const;
|
|
|
|
const CodeBlock* LookupBlock(CodeBlockKey key);
|
2019-11-19 10:30:04 +00:00
|
|
|
bool CompileBlock(CodeBlock* block);
|
|
|
|
void FlushBlock(CodeBlock* block);
|
|
|
|
void InterpretCachedBlock(const CodeBlock& block);
|
|
|
|
void InterpretUncachedBlock();
|
|
|
|
|
2019-11-19 14:15:14 +00:00
|
|
|
System* m_system;
|
2019-11-19 10:30:04 +00:00
|
|
|
Core* m_core;
|
|
|
|
Bus* m_bus;
|
|
|
|
|
|
|
|
const CodeBlock* m_current_block = nullptr;
|
|
|
|
bool m_current_block_flushed = false;
|
|
|
|
|
|
|
|
std::unique_ptr<JitCodeBuffer> m_code_buffer;
|
|
|
|
std::unique_ptr<Recompiler::ASMFunctions> m_asm_functions;
|
|
|
|
|
|
|
|
BlockMap m_blocks;
|
|
|
|
|
|
|
|
std::array<std::vector<CodeBlock*>, CPU_CODE_CACHE_PAGE_COUNT> m_ram_block_map;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool USE_CODE_CACHE;
|
|
|
|
extern bool USE_RECOMPILER;
|
|
|
|
|
|
|
|
} // namespace CPU
|