Skip to content

Commit

Permalink
jit-ir: Implement basic icache clear.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Jul 2, 2016
1 parent 6fb34d0 commit 1df0851
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Core/MIPS/IR/IRFrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ MIPSOpcode IRFrontend::GetOffsetInstruction(int offset) {
return Memory::Read_Instruction(GetCompilerPC() + 4 * offset);
}

void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants) {
void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants, u32 &mipsBytes) {
js.cancel = false;
js.blockStart = em_address;
js.compilerPC = em_address;
Expand Down Expand Up @@ -254,6 +254,8 @@ void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, std::v
}
}

mipsBytes = js.compilerPC - em_address;

IRWriter simplified;
IRWriter *code = &ir;
if (!js.hadBreakpoints) {
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRFrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class IRFrontend : public MIPSFrontendInterface {
void DoState(PointerWrap &p);
bool CheckRounding(); // returns true if we need a do-over

void DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants);
void DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants, u32 &mipsBytes);

void EatPrefix() override {
js.EatPrefix();
Expand Down
17 changes: 14 additions & 3 deletions Core/MIPS/IR/IRJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ void IRJit::Compile(u32 em_address) {

std::vector<IRInst> instructions;
std::vector<u32> constants;
frontend_.DoJit(em_address, instructions, constants);
u32 mipsBytes;
frontend_.DoJit(em_address, instructions, constants, mipsBytes);
b->SetInstructions(instructions, constants);
b->SetOriginalSize(mipsBytes);
b->Finalize(block_num); // Overwrites the first instruction

if (frontend_.CheckRounding()) {
Expand Down Expand Up @@ -152,8 +154,13 @@ void IRBlockCache::Clear() {
blocks_.clear();
}

void IRBlockCache::InvalidateICache(u32 addess, u32 length) {
// TODO
void IRBlockCache::InvalidateICache(u32 address, u32 length) {
// TODO: Could be more efficient.
for (int i = 0; i < size_; ++i) {
if (blocks_[i].OverlapsRange(address, length)) {
blocks_[i].Destroy(i);
}
}
}

std::vector<u32> IRBlockCache::SaveAndClearEmuHackOps() {
Expand Down Expand Up @@ -217,6 +224,10 @@ void IRBlock::Destroy(int number) {
}
}

bool IRBlock::OverlapsRange(u32 addr, u32 size) {
return addr + size > origAddr_ && addr < origAddr_ + origSize_;
}

MIPSOpcode IRJit::GetOriginalOp(MIPSOpcode op) {
IRBlock *b = blocks_.GetBlock(op.encoding & 0xFFFFFF);
return b->GetOriginalFirstOp();
Expand Down
7 changes: 6 additions & 1 deletion Core/MIPS/IR/IRJit.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class IRBlock {
bool HasOriginalFirstOp();
bool RestoreOriginalFirstOp(int number);
bool IsValid() const { return origAddr_ != 0; }
void SetOriginalSize(u32 size) {
origSize_ = size;
}
bool OverlapsRange(u32 addr, u32 size);

void Finalize(int number);
void Destroy(int number);
Expand All @@ -110,13 +114,14 @@ class IRBlock {
u16 numInstructions_;
u16 numConstants_;
u32 origAddr_;
u32 origSize_;
MIPSOpcode origFirstOpcode_;
};

class IRBlockCache {
public:
void Clear();
void InvalidateICache(u32 addess, u32 length);
void InvalidateICache(u32 address, u32 length);
int GetNumBlocks() const { return (int)blocks_.size(); }
int AllocateBlock(int emAddr) {
blocks_.push_back(IRBlock(emAddr));
Expand Down

0 comments on commit 1df0851

Please sign in to comment.