From cfc25edae5e368de391a269044be635ad10c9a9a Mon Sep 17 00:00:00 2001 From: dakotachasesmith Date: Thu, 2 May 2019 19:42:19 -1000 Subject: [PATCH] Rewrite float Cop1::convert(uint32_t) so that it no longer breaks strict-aliasing rules --- src/core/ee/cop1.cpp | 11 +++++++---- src/core/ee/cop1.hpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/ee/cop1.cpp b/src/core/ee/cop1.cpp index e7796aa8f..2aa8fe7a9 100644 --- a/src/core/ee/cop1.cpp +++ b/src/core/ee/cop1.cpp @@ -10,19 +10,22 @@ Cop1::Cop1() } //Returns a floating point value that may be changed to accomodate the FPU's non-compliance to the IEEE 754 standard. -float Cop1::convert(uint32_t value) +float Cop1::convert(uint32_t value) const noexcept { + float result; switch(value & 0x7F800000) { case 0x0: value &= 0x80000000; - return *(float*)&value; + break; case 0x7F800000: value = (value & 0x80000000)|0x7F7FFFFF; - return *(float*)&value; + break; default: - return *(float*)&value; + break; } + memcpy(&result, &value, sizeof(float)); + return result; } void Cop1::check_overflow(uint32_t& dest, bool set_flags) diff --git a/src/core/ee/cop1.hpp b/src/core/ee/cop1.hpp index 2dcd5fb0c..16eeb9711 100644 --- a/src/core/ee/cop1.hpp +++ b/src/core/ee/cop1.hpp @@ -30,7 +30,7 @@ class Cop1 COP1_REG gpr[32]; COP1_REG accumulator; - float convert(uint32_t value); + float convert(uint32_t value) const noexcept; void check_overflow(uint32_t& dest, bool set_flags); void check_underflow(uint32_t& dest, bool set_flags); public: