Skip to content

Commit

Permalink
Merge pull request #6617 from lioncash/ppcanalyst
Browse files Browse the repository at this point in the history
PPCAnalyst: Minor cleanup
  • Loading branch information
leoetlino committed Apr 9, 2018
2 parents 783cbef + 9c5115a commit cb88e12
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
29 changes: 15 additions & 14 deletions Source/Core/Core/PowerPC/PPCAnalyst.cpp
Expand Up @@ -479,11 +479,12 @@ void PPCAnalyzer::ReorderInstructionsCore(u32 instructions, CodeOp* code, bool r
CodeOp& b = code[i + increment];
// Reorder integer compares, rlwinm., and carry-affecting ops
// (if we add more merged branch instructions, add them here!)
if ((type == REORDER_CROR && isCror(a)) || (type == REORDER_CARRY && isCarryOp(a)) ||
(type == REORDER_CMP && (isCmp(a) || a.outputCR0)))
if ((type == ReorderType::CROR && isCror(a)) ||
(type == ReorderType::Carry && isCarryOp(a)) ||
(type == ReorderType::CMP && (isCmp(a) || a.outputCR0)))
{
// once we're next to a carry instruction, don't move away!
if (type == REORDER_CARRY && i != start)
if (type == ReorderType::Carry && i != start)
{
// if we read the CA flag, and the previous instruction sets it, don't move away.
if (!reverse && (a.opinfo->flags & FL_READ_CA) &&
Expand Down Expand Up @@ -514,16 +515,16 @@ void PPCAnalyzer::ReorderInstructions(u32 instructions, CodeOp* code)
// picky about this, but cror seems to almost solely be used for this purpose in real code.
// Additionally, the other boolean ops seem to almost never be used.
if (HasOption(OPTION_CROR_MERGE))
ReorderInstructionsCore(instructions, code, true, REORDER_CROR);
ReorderInstructionsCore(instructions, code, true, ReorderType::CROR);
// For carry, bubble instructions *towards* each other; one direction often isn't enough
// to get pairs like addc/adde next to each other.
if (HasOption(OPTION_CARRY_MERGE))
{
ReorderInstructionsCore(instructions, code, false, REORDER_CARRY);
ReorderInstructionsCore(instructions, code, true, REORDER_CARRY);
ReorderInstructionsCore(instructions, code, false, ReorderType::Carry);
ReorderInstructionsCore(instructions, code, true, ReorderType::Carry);
}
if (HasOption(OPTION_BRANCH_MERGE))
ReorderInstructionsCore(instructions, code, false, REORDER_CMP);
ReorderInstructionsCore(instructions, code, false, ReorderType::CMP);
}

void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo,
Expand All @@ -544,22 +545,22 @@ void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const Gekk
else if ((opinfo->flags & FL_SET_CRn) && code->inst.CRFD == 0)
code->outputCR0 = true;
else
code->outputCR0 = (opinfo->flags & FL_SET_CR0) ? true : false;
code->outputCR0 = (opinfo->flags & FL_SET_CR0) != 0;

// Does the instruction output CR1?
if (opinfo->flags & FL_RC_BIT_F)
code->outputCR1 = code->inst.hex & 1; // todo fix
else if ((opinfo->flags & FL_SET_CRn) && code->inst.CRFD == 1)
code->outputCR1 = true;
else
code->outputCR1 = (opinfo->flags & FL_SET_CR1) ? true : false;
code->outputCR1 = (opinfo->flags & FL_SET_CR1) != 0;

code->wantsFPRF = (opinfo->flags & FL_READ_FPRF) ? true : false;
code->outputFPRF = (opinfo->flags & FL_SET_FPRF) ? true : false;
code->canEndBlock = (opinfo->flags & FL_ENDBLOCK) ? true : false;
code->wantsFPRF = (opinfo->flags & FL_READ_FPRF) != 0;
code->outputFPRF = (opinfo->flags & FL_SET_FPRF) != 0;
code->canEndBlock = (opinfo->flags & FL_ENDBLOCK) != 0;

code->wantsCA = (opinfo->flags & FL_READ_CA) ? true : false;
code->outputCA = (opinfo->flags & FL_SET_CA) ? true : false;
code->wantsCA = (opinfo->flags & FL_READ_CA) != 0;
code->outputCA = (opinfo->flags & FL_SET_CA) != 0;

// We're going to try to avoid storing carry in XER if we can avoid it -- keep it in the x86 carry
// flag!
Expand Down
35 changes: 15 additions & 20 deletions Source/Core/Core/PowerPC/PPCAnalyst.h
Expand Up @@ -5,11 +5,7 @@
#pragma once

#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <string>
#include <vector>

#include "Common/BitSet.h"
#include "Common/CommonTypes.h"
Expand Down Expand Up @@ -166,21 +162,6 @@ struct CodeBlock

class PPCAnalyzer
{
private:
enum ReorderType
{
REORDER_CARRY,
REORDER_CMP,
REORDER_CROR
};

void ReorderInstructionsCore(u32 instructions, CodeOp* code, bool reverse, ReorderType type);
void ReorderInstructions(u32 instructions, CodeOp* code);
void SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo, u32 index);

// Options
u32 m_options;

public:
enum AnalystOption
{
Expand Down Expand Up @@ -220,12 +201,26 @@ class PPCAnalyzer
OPTION_CROR_MERGE = (1 << 6),
};

PPCAnalyzer() : m_options(0) {}
// Option setting/getting
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);

private:
enum class ReorderType
{
Carry,
CMP,
CROR
};

void ReorderInstructionsCore(u32 instructions, CodeOp* code, bool reverse, ReorderType type);
void ReorderInstructions(u32 instructions, CodeOp* code);
void SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo, u32 index);

// Options
u32 m_options = 0;
};

void LogFunctionCall(u32 addr);
Expand Down

0 comments on commit cb88e12

Please sign in to comment.