Merge pull request #6900 from lioncash/buffer

PPCAnalyst: Make CodeBuffer an alias for std::vector<CodeOp>
This commit is contained in:
Léo Lam 2018-05-19 12:10:19 +02:00 committed by GitHub
commit d399b0f59e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 64 deletions

View File

@ -194,7 +194,7 @@ void CachedInterpreter::Jit(u32 address)
ClearCache();
}
u32 nextPC = analyzer.Analyze(PC, &code_block, &code_buffer, code_buffer.GetSize());
const u32 nextPC = analyzer.Analyze(PC, &code_block, &code_buffer, code_buffer.size());
if (code_block.m_memory_exception)
{
// Address of instruction could not be translated
@ -216,10 +216,9 @@ void CachedInterpreter::Jit(u32 address)
b->checkedEntry = GetCodePtr();
b->normalEntry = GetCodePtr();
PPCAnalyst::CodeOp* const ops = code_buffer.codebuffer;
for (u32 i = 0; i < code_block.m_num_instructions; i++)
{
PPCAnalyst::CodeOp& op = ops[i];
PPCAnalyst::CodeOp& op = code_buffer[i];
js.downcountAmount += op.opinfo->numCycles;

View File

@ -594,7 +594,7 @@ void Jit64::Jit(u32 em_address)
ClearCache();
}
int blockSize = code_buffer.GetSize();
std::size_t block_size = code_buffer.size();
if (SConfig::GetInstance().bEnableDebugging)
{
@ -607,7 +607,7 @@ void Jit64::Jit(u32 em_address)
{
if (CPU::IsStepping())
{
blockSize = 1;
block_size = 1;
// Do not link this block to other blocks While single stepping
jo.enableBlocklink = false;
@ -624,7 +624,7 @@ void Jit64::Jit(u32 em_address)
// Analyze the block, collect all instructions it is made of (including inlining,
// if that is enabled), reorder instructions for optimal performance, and join joinable
// instructions.
u32 nextPC = analyzer.Analyze(em_address, &code_block, &code_buffer, blockSize);
const u32 nextPC = analyzer.Analyze(em_address, &code_block, &code_buffer, block_size);
if (code_block.m_memory_exception)
{
@ -637,11 +637,11 @@ void Jit64::Jit(u32 em_address)
}
JitBlock* b = blocks.AllocateBlock(em_address);
DoJit(em_address, &code_buffer, b, nextPC);
DoJit(em_address, b, nextPC);
blocks.FinalizeBlock(*b, jo.enableBlocklink, code_block.m_physical_addresses);
}
const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC)
const u8* Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
{
js.firstFPInstructionFound = false;
js.isLastInstruction = false;
@ -739,10 +739,9 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc
}
// Translate instructions
PPCAnalyst::CodeOp* const ops = code_buf->codebuffer;
for (u32 i = 0; i < code_block.m_num_instructions; i++)
{
PPCAnalyst::CodeOp& op = ops[i];
PPCAnalyst::CodeOp& op = code_buffer[i];
js.compilerPC = op.address;
js.op = &op;
@ -951,7 +950,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc
b->originalSize = code_block.m_num_instructions;
#ifdef JIT_LOG_X86
LogGeneratedX86(code_block.m_num_instructions, code_buf, start, b);
LogGeneratedX86(code_block.m_num_instructions, code_buffer, start, b);
#endif
return normalEntry;

View File

@ -46,7 +46,7 @@ public:
// Jit!
void Jit(u32 em_address) override;
const u8* DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC);
const u8* DoJit(u32 em_address, JitBlock* b, u32 nextPC);
BitSet32 CallerSavedRegistersInUse() const;
BitSet8 ComputeStaticGQRs(const PPCAnalyst::CodeBlock&) const;

View File

@ -127,12 +127,12 @@ bool Jitx86Base::BackPatch(u32 emAddress, SContext* ctx)
return true;
}
void LogGeneratedX86(size_t size, const PPCAnalyst::CodeBuffer* code_buffer, const u8* normalEntry,
void LogGeneratedX86(size_t size, const PPCAnalyst::CodeBuffer& code_buffer, const u8* normalEntry,
const JitBlock* b)
{
for (size_t i = 0; i < size; i++)
{
const PPCAnalyst::CodeOp& op = code_buffer->codebuffer[i];
const PPCAnalyst::CodeOp& op = code_buffer[i];
std::string temp = StringFromFormat(
"%08x %s", op.address, GekkoDisassembler::Disassemble(op.inst.hex, op.address).c_str());
DEBUG_LOG(DYNA_REC, "IR_X86 PPC: %s\n", temp.c_str());

View File

@ -13,11 +13,7 @@
#include "Core/PowerPC/Jit64Common/Jit64AsmCommon.h"
#include "Core/PowerPC/Jit64Common/TrampolineCache.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
namespace PPCAnalyst
{
class CodeBuffer;
}
#include "Core/PowerPC/PPCAnalyst.h"
// RSCRATCH and RSCRATCH2 are always scratch registers and can be used without
// limitation.
@ -46,5 +42,5 @@ public:
bool HandleFault(uintptr_t access_address, SContext* ctx) override;
};
void LogGeneratedX86(size_t size, const PPCAnalyst::CodeBuffer* code_buffer, const u8* normalEntry,
void LogGeneratedX86(size_t size, const PPCAnalyst::CodeBuffer& code_buffer, const u8* normalEntry,
const JitBlock* b);

View File

@ -553,19 +553,19 @@ void JitArm64::Jit(u32)
ClearCache();
}
int blockSize = code_buffer.GetSize();
u32 em_address = PowerPC::ppcState.pc;
std::size_t block_size = code_buffer.size();
const u32 em_address = PowerPC::ppcState.pc;
if (SConfig::GetInstance().bEnableDebugging)
{
// Comment out the following to disable breakpoints (speed-up)
blockSize = 1;
block_size = 1;
}
// Analyze the block, collect all instructions it is made of (including inlining,
// if that is enabled), reorder instructions for optimal performance, and join joinable
// instructions.
u32 nextPC = analyzer.Analyze(em_address, &code_block, &code_buffer, blockSize);
const u32 nextPC = analyzer.Analyze(em_address, &code_block, &code_buffer, block_size);
if (code_block.m_memory_exception)
{
@ -578,11 +578,11 @@ void JitArm64::Jit(u32)
}
JitBlock* b = blocks.AllocateBlock(em_address);
DoJit(em_address, &code_buffer, b, nextPC);
DoJit(em_address, b, nextPC);
blocks.FinalizeBlock(*b, jo.enableBlocklink, code_block.m_physical_addresses);
}
void JitArm64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC)
void JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
{
if (em_address == 0)
{
@ -649,10 +649,9 @@ void JitArm64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock*
fpr.Start(js.fpa);
// Translate instructions
PPCAnalyst::CodeOp* const ops = code_buf->codebuffer;
for (u32 i = 0; i < code_block.m_num_instructions; i++)
{
PPCAnalyst::CodeOp& op = ops[i];
PPCAnalyst::CodeOp& op = code_buffer[i];
js.compilerPC = op.address;
js.op = &op;

View File

@ -200,7 +200,7 @@ private:
void SafeLoadToReg(u32 dest, s32 addr, s32 offsetReg, u32 flags, s32 offset, bool update);
void SafeStoreFromReg(s32 dest, u32 value, s32 regOffset, u32 flags, s32 offset);
void DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC);
void DoJit(u32 em_address, JitBlock* b, u32 nextPC);
void DoDownCount();
void Cleanup();

View File

@ -42,17 +42,6 @@ constexpr u32 BRANCH_FOLLOWING_THRESHOLD = 2;
constexpr u32 INVALID_BRANCH_TARGET = 0xFFFFFFFF;
CodeBuffer::CodeBuffer(int size)
{
codebuffer = new PPCAnalyst::CodeOp[size];
size_ = size;
}
CodeBuffer::~CodeBuffer()
{
delete[] codebuffer;
}
static u32 EvaluateBranchTarget(UGeckoInstruction instr, u32 pc)
{
switch (instr.OPCD)
@ -653,7 +642,7 @@ void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const Gekk
}
}
u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32 blockSize)
u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, std::size_t block_size)
{
// Clear block stats
memset(block->m_stats, 0, sizeof(BlockStats));
@ -675,7 +664,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32
block->m_gqr_used = BitSet8(0);
block->m_physical_addresses.clear();
CodeOp* code = buffer->codebuffer;
CodeOp* const code = buffer->data();
bool found_exit = false;
bool found_call = false;
@ -683,7 +672,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32
u32 numFollows = 0;
u32 num_inst = 0;
for (u32 i = 0; i < blockSize; ++i)
for (std::size_t i = 0; i < block_size; ++i)
{
auto result = PowerPC::TryReadInstruction(address);
if (!result.valid)
@ -707,7 +696,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32
block->m_stats->numCycles += opinfo->numCycles;
block->m_physical_addresses.insert(result.physical_address);
SetInstructionStats(block, &code[i], opinfo, i);
SetInstructionStats(block, &code[i], opinfo, static_cast<u32>(i));
bool follow = false;
u32 destination = 0;
@ -720,7 +709,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32
// cache clearning will happen many times.
if (HasOption(OPTION_BRANCH_FOLLOW) && numFollows < BRANCH_FOLLOWING_THRESHOLD)
{
if (inst.OPCD == 18 && blockSize > 1)
if (inst.OPCD == 18 && block_size > 1)
{
// Always follow BX instructions.
// TODO: Loop unrolling might bloat the code size too much.
@ -734,7 +723,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32
}
}
else if (inst.OPCD == 16 && (inst.BO & BO_DONT_DECREMENT_FLAG) &&
(inst.BO & BO_DONT_CHECK_CONDITION) && blockSize > 1)
(inst.BO & BO_DONT_CHECK_CONDITION) && block_size > 1)
{
// Always follow unconditional BCX instructions, but they are very rare.
follow = true;
@ -832,7 +821,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32
if (block->m_num_instructions > 1)
ReorderInstructions(block->m_num_instructions, code);
if ((!found_exit && num_inst > 0) || blockSize == 1)
if ((!found_exit && num_inst > 0) || block_size == 1)
{
// We couldn't find an exit
block->m_broken = true;

View File

@ -5,7 +5,9 @@
#pragma once
#include <algorithm>
#include <cstddef>
#include <set>
#include <vector>
#include "Common/BitSet.h"
#include "Common/CommonTypes.h"
@ -113,18 +115,7 @@ struct BlockRegStats
}
};
class CodeBuffer
{
public:
CodeBuffer(int size);
~CodeBuffer();
int GetSize() const { return size_; }
PPCAnalyst::CodeOp* codebuffer;
private:
int size_;
};
using CodeBuffer = std::vector<CodeOp>;
struct CodeBlock
{
@ -205,7 +196,7 @@ public:
void SetOption(AnalystOption option) { m_options |= option; }
void ClearOption(AnalystOption option) { m_options &= ~(option); }
bool HasOption(AnalystOption option) const { return !!(m_options & option); }
u32 Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32 blockSize);
u32 Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, std::size_t block_size);
private:
enum class ReorderType

View File

@ -155,12 +155,12 @@ void JITWidget::Update()
code_block.m_gpa = &gpa;
code_block.m_fpa = &fpa;
if (analyzer.Analyze(ppc_addr, &code_block, &code_buffer, 32000) != 0xFFFFFFFF)
if (analyzer.Analyze(ppc_addr, &code_block, &code_buffer, code_buffer.size()) != 0xFFFFFFFF)
{
std::ostringstream ppc_disasm;
for (u32 i = 0; i < code_block.m_num_instructions; i++)
{
const PPCAnalyst::CodeOp& op = code_buffer.codebuffer[i];
const PPCAnalyst::CodeOp& op = code_buffer[i];
std::string opcode = GekkoDisassembler::Disassemble(op.inst.hex, op.address);
ppc_disasm << std::setfill('0') << std::setw(8) << std::hex << op.address;
ppc_disasm << " " << opcode << std::endl;

View File

@ -93,12 +93,12 @@ void CJitWindow::Compare(u32 em_address)
code_block.m_gpa = &gpa;
code_block.m_fpa = &fpa;
if (analyzer.Analyze(ppc_addr, &code_block, &code_buffer, 32000) != 0xFFFFFFFF)
if (analyzer.Analyze(ppc_addr, &code_block, &code_buffer, code_buffer.size()) != 0xFFFFFFFF)
{
std::ostringstream ppc_disasm;
for (u32 i = 0; i < code_block.m_num_instructions; i++)
{
const PPCAnalyst::CodeOp& op = code_buffer.codebuffer[i];
const PPCAnalyst::CodeOp& op = code_buffer[i];
std::string opcode = GekkoDisassembler::Disassemble(op.inst.hex, op.address);
ppc_disasm << std::setfill('0') << std::setw(8) << std::hex << op.address;
ppc_disasm << " " << opcode << std::endl;