From 399768c91b69d953fe0c2152feba2665aa79f2a3 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 11 Apr 2019 09:40:05 +0200 Subject: [PATCH] Interpreter: Fix psq_l with QUANTIZE_FLOAT. psq_l with QUANTIZE_FLOAT does not use the FPU, so it does not trim the precision of the u32 input data. We already have the helper ConvertToDouble for floating point u32->u64 convertion used in lfs, so let's use it here as well. --- .../Interpreter_LoadStorePaired.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStorePaired.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStorePaired.cpp index b65e642198..1d78e5e6d8 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStorePaired.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStorePaired.cpp @@ -226,7 +226,7 @@ static void Helper_Quantize(const PowerPC::PowerPCState* ppcs, u32 addr, u32 ins } template -std::pair LoadAndDequantize(u32 addr, u32 instW, u32 ldScale) +std::pair LoadAndDequantize(u32 addr, u32 instW, u32 ldScale) { using U = std::make_unsigned_t; @@ -243,7 +243,8 @@ std::pair LoadAndDequantize(u32 addr, u32 instW, u32 ldScale) ps0 = (float)(T)(value.first) * m_dequantizeTable[ldScale]; ps1 = (float)(T)(value.second) * m_dequantizeTable[ldScale]; } - return {ps0, ps1}; + // ps0 and ps1 always contain finite and normal numbers. So we can just cast them to double + return {static_cast(ps0), static_cast(ps1)}; } static void Helper_Dequantize(PowerPC::PowerPCState* ppcs, u32 addr, u32 instI, u32 instRD, @@ -253,8 +254,8 @@ static void Helper_Dequantize(PowerPC::PowerPCState* ppcs, u32 addr, u32 instI, EQuantizeType ldType = gqr.ld_type; unsigned int ldScale = gqr.ld_scale; - float ps0 = 0.0f; - float ps1 = 0.0f; + double ps0 = 0.0; + double ps1 = 0.0; switch (ldType) { @@ -262,14 +263,14 @@ static void Helper_Dequantize(PowerPC::PowerPCState* ppcs, u32 addr, u32 instI, if (instW) { const u32 value = ReadUnpaired(addr); - ps0 = Common::BitCast(value); - ps1 = 1.0f; + ps0 = Common::BitCast(ConvertToDouble(value)); + ps1 = 1.0; } else { const std::pair value = ReadPair(addr); - ps0 = Common::BitCast(value.first); - ps1 = Common::BitCast(value.second); + ps0 = Common::BitCast(ConvertToDouble(value.first)); + ps1 = Common::BitCast(ConvertToDouble(value.second)); } break; @@ -293,8 +294,8 @@ static void Helper_Dequantize(PowerPC::PowerPCState* ppcs, u32 addr, u32 instI, case QUANTIZE_INVALID2: case QUANTIZE_INVALID3: ASSERT_MSG(POWERPC, 0, "PS dequantize - unknown type to read"); - ps0 = 0.f; - ps1 = 0.f; + ps0 = 0.0; + ps1 = 0.0; break; }