mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-03-06 14:27:44 +00:00
CPU/Recompiler: Cleanup/combine shift immediate/variable
This commit is contained in:
parent
5b745864e3
commit
a9cbc08890
|
@ -117,13 +117,10 @@ bool CodeGenerator::CompileInstruction(const CodeBlockInstruction& cbi)
|
||||||
case InstructionFunct::sll:
|
case InstructionFunct::sll:
|
||||||
case InstructionFunct::srl:
|
case InstructionFunct::srl:
|
||||||
case InstructionFunct::sra:
|
case InstructionFunct::sra:
|
||||||
result = Compile_ShiftImmediate(cbi);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InstructionFunct::sllv:
|
case InstructionFunct::sllv:
|
||||||
case InstructionFunct::srlv:
|
case InstructionFunct::srlv:
|
||||||
case InstructionFunct::srav:
|
case InstructionFunct::srav:
|
||||||
result = Compile_ShiftVariable(cbi);
|
result = Compile_Shift(cbi);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InstructionFunct::mfhi:
|
case InstructionFunct::mfhi:
|
||||||
|
@ -878,60 +875,40 @@ bool CodeGenerator::Compile_BitwiseImmediate(const CodeBlockInstruction& cbi)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeGenerator::Compile_ShiftImmediate(const CodeBlockInstruction& cbi)
|
bool CodeGenerator::Compile_Shift(const CodeBlockInstruction& cbi)
|
||||||
{
|
{
|
||||||
InstructionPrologue(cbi, 1);
|
InstructionPrologue(cbi, 1);
|
||||||
|
|
||||||
// rd <- rt op shamt
|
const InstructionFunct funct = cbi.instruction.r.funct;
|
||||||
Value rt = m_register_cache.ReadGuestRegister(cbi.instruction.r.rt);
|
Value rt = m_register_cache.ReadGuestRegister(cbi.instruction.r.rt);
|
||||||
Value shamt = Value::FromConstantU32(cbi.instruction.r.shamt);
|
Value shamt;
|
||||||
|
if (funct == InstructionFunct::sll || funct == InstructionFunct::srl || funct == InstructionFunct::sra)
|
||||||
|
{
|
||||||
|
// rd <- rt op shamt
|
||||||
|
shamt = Value::FromConstantU32(cbi.instruction.r.shamt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// rd <- rt op (rs & 0x1F)
|
||||||
|
shamt = m_register_cache.ReadGuestRegister(cbi.instruction.r.rs);
|
||||||
|
if constexpr (!SHIFTS_ARE_IMPLICITLY_MASKED)
|
||||||
|
EmitAnd(shamt.host_reg, Value::FromConstantU32(0x1F));
|
||||||
|
}
|
||||||
|
|
||||||
Value result;
|
Value result;
|
||||||
switch (cbi.instruction.r.funct)
|
switch (cbi.instruction.r.funct)
|
||||||
{
|
{
|
||||||
case InstructionFunct::sll:
|
case InstructionFunct::sll:
|
||||||
result = ShlValues(rt, shamt);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InstructionFunct::srl:
|
|
||||||
result = ShrValues(rt, shamt);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InstructionFunct::sra:
|
|
||||||
result = SarValues(rt, shamt);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
UnreachableCode();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_register_cache.WriteGuestRegister(cbi.instruction.r.rd, std::move(result));
|
|
||||||
|
|
||||||
InstructionEpilogue(cbi);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CodeGenerator::Compile_ShiftVariable(const CodeBlockInstruction& cbi)
|
|
||||||
{
|
|
||||||
InstructionPrologue(cbi, 1);
|
|
||||||
|
|
||||||
// rd <- rt op (rs & 0x1F)
|
|
||||||
Value rt = m_register_cache.ReadGuestRegister(cbi.instruction.r.rt);
|
|
||||||
Value shamt = m_register_cache.ReadGuestRegister(cbi.instruction.r.rs);
|
|
||||||
if constexpr (!SHIFTS_ARE_IMPLICITLY_MASKED)
|
|
||||||
EmitAnd(shamt.host_reg, Value::FromConstantU32(0x1F));
|
|
||||||
|
|
||||||
Value result;
|
|
||||||
switch (cbi.instruction.r.funct)
|
|
||||||
{
|
|
||||||
case InstructionFunct::sllv:
|
case InstructionFunct::sllv:
|
||||||
result = ShlValues(rt, shamt);
|
result = ShlValues(rt, shamt);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case InstructionFunct::srl:
|
||||||
case InstructionFunct::srlv:
|
case InstructionFunct::srlv:
|
||||||
result = ShrValues(rt, shamt);
|
result = ShrValues(rt, shamt);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case InstructionFunct::sra:
|
||||||
case InstructionFunct::srav:
|
case InstructionFunct::srav:
|
||||||
result = SarValues(rt, shamt);
|
result = SarValues(rt, shamt);
|
||||||
break;
|
break;
|
||||||
|
@ -941,6 +918,7 @@ bool CodeGenerator::Compile_ShiftVariable(const CodeBlockInstruction& cbi)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_register_cache.WriteGuestRegister(cbi.instruction.r.rd, std::move(result));
|
m_register_cache.WriteGuestRegister(cbi.instruction.r.rd, std::move(result));
|
||||||
|
|
||||||
InstructionEpilogue(cbi);
|
InstructionEpilogue(cbi);
|
||||||
|
|
|
@ -174,8 +174,7 @@ private:
|
||||||
bool CompileInstruction(const CodeBlockInstruction& cbi);
|
bool CompileInstruction(const CodeBlockInstruction& cbi);
|
||||||
bool Compile_Fallback(const CodeBlockInstruction& cbi);
|
bool Compile_Fallback(const CodeBlockInstruction& cbi);
|
||||||
bool Compile_BitwiseImmediate(const CodeBlockInstruction& cbi);
|
bool Compile_BitwiseImmediate(const CodeBlockInstruction& cbi);
|
||||||
bool Compile_ShiftImmediate(const CodeBlockInstruction& cbi);
|
bool Compile_Shift(const CodeBlockInstruction& cbi);
|
||||||
bool Compile_ShiftVariable(const CodeBlockInstruction& cbi);
|
|
||||||
bool Compile_Load(const CodeBlockInstruction& cbi);
|
bool Compile_Load(const CodeBlockInstruction& cbi);
|
||||||
bool Compile_Store(const CodeBlockInstruction& cbi);
|
bool Compile_Store(const CodeBlockInstruction& cbi);
|
||||||
bool Compile_MoveHiLo(const CodeBlockInstruction& cbi);
|
bool Compile_MoveHiLo(const CodeBlockInstruction& cbi);
|
||||||
|
|
Loading…
Reference in a new issue