Skip to content
Permalink
Browse files

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.
  • Loading branch information...
degasus committed Apr 11, 2019
1 parent 849ede9 commit 399768c91b69d953fe0c2152feba2665aa79f2a3
Showing with 11 additions and 10 deletions.
  1. +11 −10 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 <typename T>
std::pair<float, float> LoadAndDequantize(u32 addr, u32 instW, u32 ldScale)
std::pair<double, double> LoadAndDequantize(u32 addr, u32 instW, u32 ldScale)
{
using U = std::make_unsigned_t<T>;

@@ -243,7 +243,8 @@ std::pair<float, float> 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<double>(ps0), static_cast<double>(ps1)};
}

static void Helper_Dequantize(PowerPC::PowerPCState* ppcs, u32 addr, u32 instI, u32 instRD,
@@ -253,23 +254,23 @@ 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)
{
case QUANTIZE_FLOAT:
if (instW)
{
const u32 value = ReadUnpaired<u32>(addr);
ps0 = Common::BitCast<float>(value);
ps1 = 1.0f;
ps0 = Common::BitCast<double>(ConvertToDouble(value));
ps1 = 1.0;
}
else
{
const std::pair<u32, u32> value = ReadPair<u32>(addr);
ps0 = Common::BitCast<float>(value.first);
ps1 = Common::BitCast<float>(value.second);
ps0 = Common::BitCast<double>(ConvertToDouble(value.first));
ps1 = Common::BitCast<double>(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;
}

0 comments on commit 399768c

Please sign in to comment.
You can’t perform that action at this time.