Skip to content

Commit

Permalink
Merge pull request #17901 from unknownbrackets/riscv-disasm
Browse files Browse the repository at this point in the history
riscv: Add debug log of block disasm
  • Loading branch information
hrydgard committed Aug 13, 2023
2 parents 7127ebb + 2bb67db commit 5dcd14b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Core/MIPS/RiscV/RiscVJit.cpp
Expand Up @@ -15,6 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <cstddef>
#include "ext/riscv-disas.h"
#include "Core/MemMap.h"
#include "Core/MIPS/MIPSTables.h"
#include "Core/MIPS/RiscV/RiscVJit.h"
Expand Down Expand Up @@ -77,10 +79,13 @@ bool RiscVJitBackend::CompileBlock(IRBlock *block, int block_num, bool preload)
gpr.Start(block);
fpr.Start(block);

std::map<const u8 *, IRInst> addresses;
for (int i = 0; i < block->GetNumInstructions(); ++i) {
const IRInst &inst = block->GetInstructions()[i];
gpr.SetIRIndex(i);
fpr.SetIRIndex(i);
// TODO: This might be a little wasteful when compiling if we're not debugging jit...
addresses[GetCodePtr()] = inst;

CompileIRInst(inst);

Expand Down Expand Up @@ -127,6 +132,30 @@ bool RiscVJitBackend::CompileBlock(IRBlock *block, int block_num, bool preload)
QuickJ(R_RA, outerLoopPCInSCRATCH1_);
}

if (logBlocks_ > 0) {
--logBlocks_;

INFO_LOG(JIT, "== RISCV ==");
INFO_LOG(JIT, "=============== RISCV (%d bytes) ===============", len);
for (const u8 *p = blockStart; p < GetCodePointer(); ) {
char temp[512];
rv_inst inst;
size_t len;

auto it = addresses.find(p);
if (it != addresses.end()) {
DisassembleIR(temp, sizeof(temp), it->second);
INFO_LOG(JIT, "IR: # %s", temp);
}

riscv_inst_fetch(p, &inst, &len);
riscv_disasm_inst(temp, sizeof(temp), rv64, (uintptr_t)p, inst);
p += len;

INFO_LOG(JIT, "RV: %s", temp);
}
}

FlushIcache();
compilingBlockNum_ = -1;

Expand Down
1 change: 1 addition & 0 deletions Core/MIPS/RiscV/RiscVJit.h
Expand Up @@ -127,6 +127,7 @@ class RiscVJitBackend : public RiscVGen::RiscVCodeBlock, public IRNativeBackend

int jitStartOffset_ = 0;
int compilingBlockNum_ = -1;
int logBlocks_ = 0;
};

class RiscVJit : public IRNativeJit {
Expand Down

0 comments on commit 5dcd14b

Please sign in to comment.