From 2343696995c6744a058e6ed7b92c137cc66c5ec1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 24 Jun 2021 16:52:38 +1000 Subject: [PATCH] CPU/Recompiler: Fix a few incorrect calls to PGXP Fixes PGXP not being effective in Grandia. --- src/core/cpu_recompiler_code_generator.cpp | 9 ++++++--- src/core/pgxp.cpp | 15 +++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/cpu_recompiler_code_generator.cpp b/src/core/cpu_recompiler_code_generator.cpp index f467da3ea..6ca207450 100644 --- a/src/core/cpu_recompiler_code_generator.cpp +++ b/src/core/cpu_recompiler_code_generator.cpp @@ -1874,7 +1874,10 @@ bool CodeGenerator::Compile_Multiply(const CodeBlockInstruction& cbi) Value rs = m_register_cache.ReadGuestRegister(cbi.instruction.r.rs); Value rt = m_register_cache.ReadGuestRegister(cbi.instruction.r.rt); if (g_settings.UsingPGXPCPUMode()) - EmitFunctionCall(nullptr, signed_multiply ? &PGXP::CPU_MULT : &PGXP::CPU_MULTU, rs, rt); + { + EmitFunctionCall(nullptr, signed_multiply ? &PGXP::CPU_MULT : &PGXP::CPU_MULTU, + Value::FromConstantU32(cbi.instruction.bits), rs, rt); + } std::pair result = MulValues(rs, rt, signed_multiply); rs.ReleaseAndClear(); @@ -1937,7 +1940,7 @@ bool CodeGenerator::Compile_Divide(const CodeBlockInstruction& cbi) Value denom = m_register_cache.ReadGuestRegister(cbi.instruction.r.rt); if (g_settings.UsingPGXPCPUMode()) - EmitFunctionCall(nullptr, &PGXP::CPU_DIV, num, denom); + EmitFunctionCall(nullptr, &PGXP::CPU_DIV, Value::FromConstantU32(cbi.instruction.bits), num, denom); if (num.IsConstant() && denom.IsConstant()) { @@ -1998,7 +2001,7 @@ bool CodeGenerator::Compile_SignedDivide(const CodeBlockInstruction& cbi) Value denom = m_register_cache.ReadGuestRegister(cbi.instruction.r.rt); if (g_settings.UsingPGXPCPUMode()) - EmitFunctionCall(nullptr, &PGXP::CPU_DIVU, num, denom); + EmitFunctionCall(nullptr, &PGXP::CPU_DIV, Value::FromConstantU32(cbi.instruction.bits), num, denom); if (num.IsConstant() && denom.IsConstant()) { diff --git a/src/core/pgxp.cpp b/src/core/pgxp.cpp index 70d477209..a15d34d86 100644 --- a/src/core/pgxp.cpp +++ b/src/core/pgxp.cpp @@ -185,7 +185,7 @@ ALWAYS_INLINE_RELEASE void ValidateAndCopyMem(PGXP_value* dest, u32 addr, u32 va *dest = PGXP_value_invalid; } -static void ValidateAndCopyMem16(PGXP_value* dest, u32 addr, u32 value, int sign) +ALWAYS_INLINE_RELEASE static void ValidateAndCopyMem16(PGXP_value* dest, u32 addr, u32 value, int sign) { u32 validMask = 0; psx_value val, mask; @@ -236,7 +236,7 @@ ALWAYS_INLINE_RELEASE void WriteMem(const PGXP_value* value, u32 addr) *pMem = *value; } -static void WriteMem16(PGXP_value* src, u32 addr) +ALWAYS_INLINE_RELEASE static void WriteMem16(const PGXP_value* src, u32 addr) { PGXP_value* dest = GetPtr(addr); psx_value* pVal = NULL; @@ -599,16 +599,19 @@ void CPU_SB(u32 instr, u8 rtVal, u32 addr) void CPU_SH(u32 instr, u16 rtVal, u32 addr) { + PGXP_value* val = &CPU_reg[rt(instr)]; + // validate and copy half value - MaskValidate(&CPU_reg[rt(instr)], rtVal, 0xFFFF, VALID_0); - WriteMem16(&CPU_reg[rt(instr)], addr); + MaskValidate(val, rtVal, 0xFFFF, VALID_0); + WriteMem16(val, addr); } void CPU_SW(u32 instr, u32 rtVal, u32 addr) { // Mem[Rs + Im] = Rt - Validate(&CPU_reg[rt(instr)], rtVal); - WriteMem(&CPU_reg[rt(instr)], addr); + PGXP_value* val = &CPU_reg[rt(instr)]; + Validate(val, rtVal); + WriteMem(val, addr); } void CPU_MOVE(u32 rd_and_rs, u32 rsVal)