PPU/LLVM: Replace magic number with opcode enum in GetBranchTypeFromInstruction.

This commit is contained in:
Vincent Lejeune 2015-08-17 21:51:57 +02:00
parent 99a9fd8505
commit f81192373f
1 changed files with 11 additions and 9 deletions

View File

@ -701,23 +701,25 @@ u32 ppu_recompiler_llvm::CPUHybridDecoderRecompiler::ExecuteFunction(PPUThread *
} }
/// Get the branch type from a branch instruction /// Get the branch type from a branch instruction
static BranchType GetBranchTypeFromInstruction(u32 instruction) { static BranchType GetBranchTypeFromInstruction(u32 instruction)
u32 field1 = instruction >> 26; {
u32 instructionOpcode = PPU_instr::fields::OPCD(instruction);
u32 lk = instruction & 1; u32 lk = instruction & 1;
if (field1 == 16 || field1 == 18) if (instructionOpcode == PPU_opcodes::PPU_MainOpcodes::B ||
instructionOpcode == PPU_opcodes::PPU_MainOpcodes::BC)
return lk ? BranchType::FunctionCall : BranchType::LocalBranch; return lk ? BranchType::FunctionCall : BranchType::LocalBranch;
if (field1 == 19) { if (instructionOpcode == PPU_opcodes::PPU_MainOpcodes::G_13) {
u32 field2 = (instruction >> 1) & 0x3FF; u32 G13Opcode = PPU_instr::fields::GD_13(instruction);
if (field2 == 16) if (G13Opcode == PPU_opcodes::G_13Opcodes::BCLR)
return lk ? BranchType::FunctionCall : BranchType::Return; return lk ? BranchType::FunctionCall : BranchType::Return;
if (field2 == 528) if (G13Opcode == PPU_opcodes::G_13Opcodes::BCCTR)
return lk ? BranchType::FunctionCall : BranchType::LocalBranch; return lk ? BranchType::FunctionCall : BranchType::LocalBranch;
return BranchType::NonBranch; return BranchType::NonBranch;
} }
if (field1 == 1 && (instruction & EIF_PERFORM_BLR)) // classify HACK instruction if (instructionOpcode == PPU_opcodes::PPU_MainOpcodes::HACK && (instruction & EIF_PERFORM_BLR)) // classify HACK instruction
return instruction & EIF_USE_BRANCH ? BranchType::FunctionCall : BranchType::Return; return instruction & EIF_USE_BRANCH ? BranchType::FunctionCall : BranchType::Return;
if (field1 == 1 && (instruction & EIF_USE_BRANCH)) if (instructionOpcode == PPU_opcodes::PPU_MainOpcodes::HACK && (instruction & EIF_USE_BRANCH))
return BranchType::LocalBranch; return BranchType::LocalBranch;
return BranchType::NonBranch; return BranchType::NonBranch;
} }