From d8ed251ad1205f0491bd79a3c6012f3e3b197fc9 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Mon, 6 Mar 2017 01:04:59 -0600 Subject: [PATCH] Tests: Handle integer floating point numbers --- src/xenia/base/vec128.h | 13 +++++++++++++ src/xenia/cpu/ppc/ppc_context.cc | 27 ++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/xenia/base/vec128.h b/src/xenia/base/vec128.h index 9d694a5f0..68d06744a 100644 --- a/src/xenia/base/vec128.h +++ b/src/xenia/base/vec128.h @@ -171,6 +171,19 @@ static inline vec128_t vec128i(uint32_t x, uint32_t y, uint32_t z, uint32_t w) { v.u32[3] = w; return v; } +static inline vec128_t vec128q(uint64_t src) { + vec128_t v; + for (auto i = 0; i < 2; ++i) { + v.i64[i] = src; + } + return v; +} +static inline vec128_t vec128q(uint64_t x, uint64_t y) { + vec128_t v; + v.i64[0] = x; + v.i64[1] = y; + return v; +} static inline vec128_t vec128d(double src) { vec128_t v; for (auto i = 0; i < 2; ++i) { diff --git a/src/xenia/cpu/ppc/ppc_context.cc b/src/xenia/cpu/ppc/ppc_context.cc index 5e6594bcd..4143d21a6 100644 --- a/src/xenia/cpu/ppc/ppc_context.cc +++ b/src/xenia/cpu/ppc/ppc_context.cc @@ -147,11 +147,28 @@ bool PPCContext::CompareRegWithString(const char* name, const char* value, } return true; } else if (sscanf(name, "f%d", &n) == 1) { - double expected = string_util::from_string(value); - // TODO(benvanik): epsilon - if (this->f[n] != expected) { - std::snprintf(out_value, out_value_size, "%f", this->f[n]); - return false; + if (std::strstr(value, "0x")) { + // Special case: Treat float as integer. + uint64_t expected = string_util::from_string(value, true); + + union { + double f; + uint64_t u; + } f2u; + f2u.f = this->f[n]; + + if (f2u.u != expected) { + std::snprintf(out_value, out_value_size, "%016" PRIX64, f2u.u); + return false; + } + } else { + double expected = string_util::from_string(value); + + // TODO(benvanik): epsilon + if (this->f[n] != expected) { + std::snprintf(out_value, out_value_size, "%f", this->f[n]); + return false; + } } return true; } else if (sscanf(name, "v%d", &n) == 1) {