Skip to content

Commit

Permalink
PPCRec: Dead code elimination + reintroduce pre-rework optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Exzap committed Jan 13, 2024
1 parent 7b04057 commit a671611
Show file tree
Hide file tree
Showing 11 changed files with 902 additions and 291 deletions.
50 changes: 50 additions & 0 deletions src/Cafe/HW/Espresso/Recompiler/BackendX64/BackendX64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ X86Cond _x86Cond(IMLCondition imlCond)
return X86_CONDITION_Z;
}

X86Cond _x86CondInverted(IMLCondition imlCond)
{
switch (imlCond)
{
case IMLCondition::EQ:
return X86_CONDITION_NZ;
case IMLCondition::NEQ:
return X86_CONDITION_Z;
case IMLCondition::UNSIGNED_GT:
return X86_CONDITION_BE;
case IMLCondition::UNSIGNED_LT:
return X86_CONDITION_NB;
case IMLCondition::SIGNED_GT:
return X86_CONDITION_LE;
case IMLCondition::SIGNED_LT:
return X86_CONDITION_NL;
default:
break;
}
cemu_assert_suspicious();
return X86_CONDITION_Z;
}

X86Cond _x86Cond(IMLCondition imlCond, bool condIsInverted)
{
if (condIsInverted)
return _x86CondInverted(imlCond);
return _x86Cond(imlCond);
}

/*
* Remember current instruction output offset for reloc
* The instruction generated after this method has been called will be adjusted
Expand Down Expand Up @@ -638,6 +668,10 @@ bool PPCRecompilerX64Gen_imlInstruction_r_r(PPCRecFunction_t* PPCRecFunction, pp
PPCRecompilerX64Gen_redirectRelativeJump(x64GenContext, jumpInstructionOffset2, x64GenContext->emitter->GetWriteIndex());
}
}
else if( imlInstruction->operation == PPCREC_IML_OP_X86_CMP)
{
x64GenContext->emitter->CMP_dd(regR, regA);
}
else if( imlInstruction->operation == PPCREC_IML_OP_DCBZ )
{
if( regR != regA )
Expand Down Expand Up @@ -680,6 +714,11 @@ bool PPCRecompilerX64Gen_imlInstruction_r_s32(PPCRecFunction_t* PPCRecFunction,
cemu_assert_debug((imlInstruction->op_r_immS32.immS32 & 0x80) == 0);
x64Gen_rol_reg64Low32_imm8(x64GenContext, regR, (uint8)imlInstruction->op_r_immS32.immS32);
}
else if( imlInstruction->operation == PPCREC_IML_OP_X86_CMP)
{
sint32 imm = imlInstruction->op_r_immS32.immS32;
x64GenContext->emitter->CMP_di32(regR, imm);
}
else
{
debug_printf("PPCRecompilerX64Gen_imlInstruction_r_s32(): Unsupported operation 0x%x\n", imlInstruction->operation);
Expand Down Expand Up @@ -1082,6 +1121,13 @@ bool PPCRecompilerX64Gen_imlInstruction_cjump2(PPCRecFunction_t* PPCRecFunction,
return true;
}

void PPCRecompilerX64Gen_imlInstruction_x86_eflags_jcc(PPCRecFunction_t* PPCRecFunction, ppcImlGenContext_t* ppcImlGenContext, x64GenContext_t* x64GenContext, IMLInstruction* imlInstruction, IMLSegment* imlSegment)
{
X86Cond cond = _x86Cond(imlInstruction->op_x86_eflags_jcc.cond, imlInstruction->op_x86_eflags_jcc.invertedCondition);
PPCRecompilerX64Gen_rememberRelocatableOffset(x64GenContext, imlSegment->nextSegmentBranchTaken);
x64GenContext->emitter->Jcc_j32(cond, 0);
}

bool PPCRecompilerX64Gen_imlInstruction_jump2(PPCRecFunction_t* PPCRecFunction, ppcImlGenContext_t* ppcImlGenContext, x64GenContext_t* x64GenContext, IMLInstruction* imlInstruction, IMLSegment* imlSegment)
{
PPCRecompilerX64Gen_rememberRelocatableOffset(x64GenContext, imlSegment->nextSegmentBranchTaken);
Expand Down Expand Up @@ -1504,6 +1550,10 @@ bool PPCRecompiler_generateX64Code(PPCRecFunction_t* PPCRecFunction, ppcImlGenCo
if (PPCRecompilerX64Gen_imlInstruction_cjump2(PPCRecFunction, ppcImlGenContext, &x64GenContext, imlInstruction, segIt) == false)
codeGenerationFailed = true;
}
else if(imlInstruction->type == PPCREC_IML_TYPE_X86_EFLAGS_JCC)
{
PPCRecompilerX64Gen_imlInstruction_x86_eflags_jcc(PPCRecFunction, ppcImlGenContext, &x64GenContext, imlInstruction, segIt);
}
else if (imlInstruction->type == PPCREC_IML_TYPE_JUMP)
{
if (PPCRecompilerX64Gen_imlInstruction_jump2(PPCRecFunction, ppcImlGenContext, &x64GenContext, imlInstruction, segIt) == false)
Expand Down
3 changes: 3 additions & 0 deletions src/Cafe/HW/Espresso/Recompiler/IML/IML.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ void IMLOptimizer_OptimizeDirectFloatCopies(struct ppcImlGenContext_t* ppcImlGen
void IMLOptimizer_OptimizeDirectIntegerCopies(struct ppcImlGenContext_t* ppcImlGenContext);
void PPCRecompiler_optimizePSQLoadAndStore(struct ppcImlGenContext_t* ppcImlGenContext);

void IMLOptimizer_StandardOptimizationPass(ppcImlGenContext_t& ppcImlGenContext);

// debug
void IMLDebug_DisassembleInstruction(const IMLInstruction& inst, std::string& disassemblyLineOut);
void IMLDebug_DumpSegment(struct ppcImlGenContext_t* ctx, IMLSegment* imlSegment, bool printLivenessRangeInfo = false);
void IMLDebug_Dump(struct ppcImlGenContext_t* ppcImlGenContext, bool printLivenessRangeInfo = false);
Loading

0 comments on commit a671611

Please sign in to comment.