Interpreter_LoadStorePaired: Don't use a union to type-pun between integral and FP types

This commit is contained in:
Lioncash 2018-04-11 19:01:17 -04:00
parent 7a3158a693
commit ab25eb6449
1 changed files with 19 additions and 11 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cstring>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -172,21 +173,28 @@ void Interpreter::Helper_Quantize(u32 addr, u32 instI, u32 instRS, u32 instW)
const EQuantizeType stType = gqr.st_type; const EQuantizeType stType = gqr.st_type;
const unsigned int stScale = gqr.st_scale; const unsigned int stScale = gqr.st_scale;
double ps0 = rPS0(instRS); const double ps0 = rPS0(instRS);
double ps1 = rPS1(instRS); const double ps1 = rPS1(instRS);
switch (stType) switch (stType)
{ {
case QUANTIZE_FLOAT: case QUANTIZE_FLOAT:
{ {
u32 convPS0 = ConvertToSingleFTZ(MathUtil::IntDouble(ps0).i); u64 integral_ps0;
std::memcpy(&integral_ps0, &ps0, sizeof(u64));
const u32 conv_ps0 = ConvertToSingleFTZ(integral_ps0);
if (instW) if (instW)
{ {
WriteUnpaired<u32>(convPS0, addr); WriteUnpaired<u32>(conv_ps0, addr);
} }
else else
{ {
u32 convPS1 = ConvertToSingleFTZ(MathUtil::IntDouble(ps1).i); u64 integral_ps1;
WritePair<u32>(convPS0, convPS1, addr); std::memcpy(&integral_ps1, &ps1, sizeof(double));
const u32 conv_ps1 = ConvertToSingleFTZ(integral_ps1);
WritePair<u32>(conv_ps0, conv_ps1, addr);
} }
break; break;
} }
@ -249,15 +257,15 @@ void Interpreter::Helper_Dequantize(u32 addr, u32 instI, u32 instRD, u32 instW)
case QUANTIZE_FLOAT: case QUANTIZE_FLOAT:
if (instW) if (instW)
{ {
u32 value = ReadUnpaired<u32>(addr); const u32 value = ReadUnpaired<u32>(addr);
ps0 = MathUtil::IntFloat(value).f; std::memcpy(&ps0, &value, sizeof(float));
ps1 = 1.0f; ps1 = 1.0f;
} }
else else
{ {
std::pair<u32, u32> value = ReadPair<u32>(addr); const std::pair<u32, u32> value = ReadPair<u32>(addr);
ps0 = MathUtil::IntFloat(value.first).f; std::memcpy(&ps0, &value.first, sizeof(float));
ps1 = MathUtil::IntFloat(value.second).f; std::memcpy(&ps1, &value.second, sizeof(float));
} }
break; break;