From ee1fd7baf318709eebb22555e21f8aeae4cd3759 Mon Sep 17 00:00:00 2001 From: Simone Date: Tue, 16 Jan 2024 12:15:31 +0100 Subject: [PATCH] FGR improvements --- src/backend/core/registers/Cop1.hpp | 5 +- .../core/registers/cop/cop1instructions.cpp | 278 ++++++++++-------- src/common.hpp | 6 +- 3 files changed, 169 insertions(+), 120 deletions(-) diff --git a/src/backend/core/registers/Cop1.hpp b/src/backend/core/registers/Cop1.hpp index 053b17da..a42bb4c7 100644 --- a/src/backend/core/registers/Cop1.hpp +++ b/src/backend/core/registers/Cop1.hpp @@ -108,8 +108,9 @@ struct Cop1 { void SetCauseOverflow(); void SetCauseInvalid(); private: - template - auto FGR(Cop0Status&, u32) -> T&; + template auto FGR_T(Cop0Status&, u32) -> T&; + template auto FGR_S(Cop0Status&, u32) -> T&; + template auto FGR_D(Cop0Status&, u32) -> T&; void decodeInterp(Interpreter&, u32); void decodeJIT(JIT&, u32); void absd(Registers&, u32 instr); diff --git a/src/backend/core/registers/cop/cop1instructions.cpp b/src/backend/core/registers/cop/cop1instructions.cpp index 6138e5b7..266d6aec 100644 --- a/src/backend/core/registers/cop/cop1instructions.cpp +++ b/src/backend/core/registers/cop/cop1instructions.cpp @@ -7,7 +7,7 @@ #include namespace n64 { -template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> s32& { +template<> auto Cop1::FGR_T(Cop0Status& status, u32 index) -> s32& { if (status.fr) { return fgr[index].int32; } else { @@ -19,38 +19,86 @@ template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> s32& { } } -template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> u32& { - return (u32&)FGR(status, index); +template<> auto Cop1::FGR_T(Cop0Status& status, u32 index) -> u32& { + return (u32&)FGR_T(status, index); } -template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> float& { +template<> auto Cop1::FGR_S(Cop0Status& status, u32 index) -> s32& { if (status.fr) { - return fgr[index].float32; + return fgr[index].int32; } else { - if (index & 1) { - return fgr[index & ~1].float32h; - } else { - return fgr[index].float32; - } + return fgr[index & ~1].int32; } } -template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> s64& { +template<> auto Cop1::FGR_S(Cop0Status& status, u32 index) -> u32& { + return (u32&)FGR_S(status, index); +} + +template<> auto Cop1::FGR_D(Cop0Status& status, u32 index) -> s32& { + fgr[index].int32h = 0; + return fgr[index].int32; +} + +template<> auto Cop1::FGR_T(Cop0Status& status, u32 index) -> float& { + return fgr[index].float32; +} + +template<> auto Cop1::FGR_D(Cop0Status& status, u32 index) -> float& { + fgr[index].float32h = 0; + return fgr[index].float32; +} + +template<> auto Cop1::FGR_S(Cop0Status& status, u32 index) -> float& { + if (status.fr) { + return fgr[index].float32; + } else { + return fgr[index & ~1].float32; + } +} + +template<> auto Cop1::FGR_T(Cop0Status& status, u32 index) -> s64& { if (status.fr) { return fgr[index].int64; - } else { + } + else { return fgr[index & ~1].int64; } } -template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> u64& { - return (u64&)FGR(status, index); +template<> auto Cop1::FGR_D(Cop0Status&, u32 index) -> s64& { + return fgr[index].int64; } -template<> auto Cop1::FGR(Cop0Status& status, u32 index) -> double& { +template<> auto Cop1::FGR_S(Cop0Status& status, u32 index) -> s64& { + return FGR_T(status, index); +} + +template<> auto Cop1::FGR_T(Cop0Status& status, u32 index) -> u64& { + return (u64&)FGR_T(status, index); +} + +template<> auto Cop1::FGR_D(Cop0Status& status, u32 index) -> u64& { + return (u64&)FGR_D(status, index); +} + +template<> auto Cop1::FGR_S(Cop0Status& status, u32 index) -> u64& { + return FGR_T(status, index); +} + +template<> auto Cop1::FGR_T(Cop0Status&, u32 index) -> double& { + return fgr[index].float64; +} + +template<> auto Cop1::FGR_D(Cop0Status& status, u32 index) -> double& { + return FGR_T(status, index); +} + +template<> auto Cop1::FGR_S(Cop0Status& status, u32 index) -> double& { if (status.fr) { return fgr[index].float64; - } else { + } + else { return fgr[index & ~1].float64; } } @@ -126,14 +174,14 @@ void Cop1::SetCauseInvalid() { #define OP(T, op) do { \ CheckFPUUsable(); \ - auto fs = FGR(regs.cop0.status, FS(instr)); \ - auto ft = FGR(regs.cop0.status, FT(instr)); \ + auto fs = FS(T, instr); \ + auto ft = FT(T, instr); \ CheckArg(fs); \ CheckArg(ft); \ T result; \ OP_CheckExcept({result = (op);}); \ CheckResult(result); \ - FGR(regs.cop0.status, FD(instr)) = result; \ + FD(T, instr) = result; \ } while(0) template @@ -378,42 +426,42 @@ void Cop1::addd(Registers& regs, u32 instr) { void Cop1::ceills(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::ceil(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::ceilws(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::ceil(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::ceilld(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::ceil(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::ceilwd(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::ceil(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::cfc1(Registers& regs, u32 instr) const { @@ -455,36 +503,36 @@ void Cop1::ctc1(Registers& regs, u32 instr) { void Cop1::cvtds(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckArg(fs); double result; OP_CheckExcept({ result = double(fs); }); CheckResult(result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(double, instr) = result; } void Cop1::cvtsd(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckArg(fs); float result; OP_CheckExcept({ result = float(fs); }); CheckResult(result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(float, instr) = result; } void Cop1::cvtsw(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(s32, instr); float result; OP_CheckExcept({ result = float(fs); }); CheckResult(result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(float, instr) = result; } void Cop1::cvtsl(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(s64, instr); if (fs >= s64(0x0080000000000000) || fs < s64(0xff80000000000000)) { SetCauseUnimplemented(); CheckFPUException(); @@ -492,57 +540,57 @@ void Cop1::cvtsl(Registers& regs, u32 instr) { float result; OP_CheckExcept({ result = float(fs); }); CheckResult(result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(float, instr) = result; } void Cop1::cvtwd(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckWCVTArg(fs); s32 result; PUSHROUNDING; CVT_OP_CheckExcept({ result = std::rint(fs); }); POPROUNDING; CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::cvtws(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckWCVTArg(fs); s32 result; PUSHROUNDING; CVT_OP_CheckExcept({ result = std::rint(fs); }); POPROUNDING; CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::cvtls(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckLCVTArg(fs); s64 result; PUSHROUNDING; CVT_OP_CheckExcept({ result = std::rint(fs); }); POPROUNDING; CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::cvtdw(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(s32, instr); double result; OP_CheckExcept({ result = double(fs); }); CheckResult(result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(double, instr) = result; } void Cop1::cvtdl(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(s64, instr); if (fs >= s64(0x0080000000000000) || fs < s64(0xff80000000000000)) { SetCauseUnimplemented(); @@ -551,26 +599,26 @@ void Cop1::cvtdl(Registers& regs, u32 instr) { double result; OP_CheckExcept({ result = double(fs); }); CheckResult(result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(double, instr) = result; } void Cop1::cvtld(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckLCVTArg(fs); s64 result; PUSHROUNDING; CVT_OP_CheckExcept({ result = std::rint(fs); }); POPROUNDING; CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } template void Cop1::cf(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = false; } @@ -578,8 +626,8 @@ void Cop1::cf(Registers& regs, u32 instr) { template void Cop1::cun(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = any_unordered(fs, ft); } @@ -587,8 +635,8 @@ void Cop1::cun(Registers& regs, u32 instr) { template void Cop1::ceq(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = fs == ft; } @@ -596,8 +644,8 @@ void Cop1::ceq(Registers& regs, u32 instr) { template void Cop1::cueq(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = fs == ft || any_unordered(fs, ft); } @@ -605,8 +653,8 @@ void Cop1::cueq(Registers& regs, u32 instr) { template void Cop1::colt(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = fs < ft; } @@ -614,8 +662,8 @@ void Cop1::colt(Registers& regs, u32 instr) { template void Cop1::cult(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = fs < ft || any_unordered(fs, ft); } @@ -623,8 +671,8 @@ void Cop1::cult(Registers& regs, u32 instr) { template void Cop1::cole(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = fs <= ft; } @@ -632,8 +680,8 @@ void Cop1::cole(Registers& regs, u32 instr) { template void Cop1::cule(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checkqnanregs(fs, ft); fcr31.compare = fs <= ft || any_unordered(fs, ft); } @@ -641,8 +689,8 @@ void Cop1::cule(Registers& regs, u32 instr) { template void Cop1::csf(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = false; } @@ -650,8 +698,8 @@ void Cop1::csf(Registers& regs, u32 instr) { template void Cop1::cngle(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = any_unordered(fs, ft); } @@ -659,8 +707,8 @@ void Cop1::cngle(Registers& regs, u32 instr) { template void Cop1::cseq(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = fs == ft; } @@ -668,8 +716,8 @@ void Cop1::cseq(Registers& regs, u32 instr) { template void Cop1::cngl(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = fs == ft || any_unordered(fs, ft); } @@ -677,8 +725,8 @@ void Cop1::cngl(Registers& regs, u32 instr) { template void Cop1::clt(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = fs < ft; } @@ -686,8 +734,8 @@ void Cop1::clt(Registers& regs, u32 instr) { template void Cop1::cnge(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = fs < ft || any_unordered(fs, ft); } @@ -695,8 +743,8 @@ void Cop1::cnge(Registers& regs, u32 instr) { template void Cop1::cle(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = fs <= ft; } @@ -704,8 +752,8 @@ void Cop1::cle(Registers& regs, u32 instr) { template void Cop1::cngt(Registers& regs, u32 instr) { CheckFPUUsable(); - T fs = FGR(regs.cop0.status, FS(instr)); - T ft = FGR(regs.cop0.status, FT(instr)); + T fs = FS(T, instr); + T ft = FT(T, instr); checknanregs(fs, ft); fcr31.compare = fs <= ft || any_unordered(fs, ft); } @@ -769,14 +817,14 @@ void Cop1::subd(Registers ®s, u32 instr) { void Cop1::movs(Registers& regs, u32 instr) { CheckFPUUsable_PreserveCause(); - auto val = FGR(regs.cop0.status, FS(instr)); - FGR(regs.cop0.status, FD(instr)) = val; + auto val = FS(u64, instr); + FD(u64, instr) = val; } void Cop1::movd(Registers& regs, u32 instr) { CheckFPUUsable_PreserveCause(); - auto val = FGR(regs.cop0.status, FS(instr)); - FGR(regs.cop0.status, FD(instr)) = val; + auto val = FS(double, instr); + FD(double, instr) = val; } void Cop1::negs(Registers ®s, u32 instr) { @@ -797,122 +845,122 @@ void Cop1::sqrtd(Registers ®s, u32 instr) { void Cop1::roundls(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::nearbyint(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::roundld(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::nearbyint(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::roundws(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::nearbyint(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::roundwd(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::nearbyint(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::floorls(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::floor(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::floorld(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::floor(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::floorws(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::floor(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::floorwd(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::floor(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::truncws(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::trunc(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::truncwd(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckWCVTArg(fs); s32 result; CVT_OP_CheckExcept({ result = std::trunc(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s32, instr) = result; } void Cop1::truncls(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(float, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::trunc(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } void Cop1::truncld(Registers& regs, u32 instr) { CheckFPUUsable(); - auto fs = FGR(regs.cop0.status, FS(instr)); + auto fs = FS(double, instr); CheckLCVTArg(fs); s64 result; CVT_OP_CheckExcept({ result = std::trunc(fs); }); CheckRound(fs, result); - FGR(regs.cop0.status, FD(instr)) = result; + FD(s64, instr) = result; } template @@ -988,7 +1036,7 @@ void Cop1::lwc1Interp(Registers& regs, Mem& mem, u32 instr) { FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, LOAD), 0, regs.oldPC); } else { u32 data = mem.Read(regs, physical); - FGR(regs.cop0.status, FT(instr)) = data; + FT(u32, instr) = data; } } @@ -1000,7 +1048,7 @@ void Cop1::swc1Interp(Registers& regs, Mem& mem, u32 instr) { HandleTLBException(regs, addr); FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, STORE), 0, regs.oldPC); } else { - mem.Write(regs, physical, FGR(regs.cop0.status, FT(instr))); + mem.Write(regs, physical, FT(u32, instr)); } } @@ -1019,7 +1067,7 @@ void Cop1::ldc1Interp(Registers& regs, Mem& mem, u32 instr) { FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, LOAD), 0, regs.oldPC); } else { u64 data = mem.Read(regs, physical); - FGR(regs.cop0.status, FT(instr)) = data; + FT(u64, instr) = data; } } @@ -1031,28 +1079,28 @@ void Cop1::sdc1Interp(Registers& regs, Mem& mem, u32 instr) { HandleTLBException(regs, addr); FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, STORE), 0, regs.oldPC); } else { - mem.Write(regs, physical, FGR(regs.cop0.status, FT(instr))); + mem.Write(regs, physical, FT(u64, instr)); } } void Cop1::mfc1(Registers& regs, u32 instr) { CheckFPUUsable_PreserveCause(); - regs.gpr[RT(instr)] = FGR(regs.cop0.status, FS(instr)); + regs.gpr[RT(instr)] = (u64)FS(s32, instr); } void Cop1::dmfc1(Registers& regs, u32 instr) { CheckFPUUsable_PreserveCause(); - regs.gpr[RT(instr)] = FGR(regs.cop0.status, FS(instr)); + regs.gpr[RT(instr)] = (u64)FS(s64, instr); } void Cop1::mtc1(Registers& regs, u32 instr) { CheckFPUUsable_PreserveCause(); - FGR(regs.cop0.status, FS(instr)) = regs.gpr[RT(instr)]; + FS(u32, instr) = (u64)regs.gpr[RT(instr)]; } void Cop1::dmtc1(Registers& regs, u32 instr) { CheckFPUUsable_PreserveCause(); - FGR(regs.cop0.status, FS(instr)) = regs.gpr[RT(instr)]; + FS(u64, instr) = (u64)regs.gpr[RT(instr)]; } } diff --git a/src/common.hpp b/src/common.hpp index 989ae9d9..e90e8239 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -42,9 +42,9 @@ static FORCE_INLINE constexpr u32 GetVideoFrequency(bool pal) { #define RD(x) (((x) >> 11) & 0x1F) #define RT(x) (((x) >> 16) & 0x1F) #define RS(x) (((x) >> 21) & 0x1F) -#define FD(x) (((x) >> 6) & 0x1F) -#define FT(x) RT(x) -#define FS(x) RD(x) +#define FD(type, x) FGR_D(regs.cop0.status, (((x) >> 6) & 0x1F)) +#define FT(type, x) FGR_T(regs.cop0.status, RT((x))) +#define FS(type, x) FGR_S(regs.cop0.status, RD((x))) #define BASE(x) RS(x) #define VT(x) (((x) >> 16) & 0x1F) #define VS(x) (((x) >> 11) & 0x1F)