From 0188d5ca0762c9e4fe824c1f348aca67d85ac030 Mon Sep 17 00:00:00 2001 From: aliaspider Date: Sat, 5 May 2018 18:40:56 +0100 Subject: [PATCH] fix IR interpreter on big-endian machines. --- Core/MIPS/IR/IRInterpreter.cpp | 30 ++++++++++++++++-------------- Core/MemMap.h | 8 ++++---- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Core/MIPS/IR/IRInterpreter.cpp b/Core/MIPS/IR/IRInterpreter.cpp index 045b69f469f5..62264e9228e9 100644 --- a/Core/MIPS/IR/IRInterpreter.cpp +++ b/Core/MIPS/IR/IRInterpreter.cpp @@ -618,45 +618,47 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, int count) { case IROp::Mult: { s64 result = (s64)(s32)mips->r[inst->src1] * (s64)(s32)mips->r[inst->src2]; - memcpy(&mips->lo, &result, 8); + mips->lo = (u32)result; + mips->hi = (u32)(result >> 32); break; } case IROp::MultU: { u64 result = (u64)mips->r[inst->src1] * (u64)mips->r[inst->src2]; - memcpy(&mips->lo, &result, 8); + mips->lo = (u32)result; + mips->hi = (u32)(result >> 32); break; } case IROp::Madd: { - s64 result; - memcpy(&result, &mips->lo, 8); + s64 result = (s64)((u64)mips->lo | ((u64)mips->hi << 32)); result += (s64)(s32)mips->r[inst->src1] * (s64)(s32)mips->r[inst->src2]; - memcpy(&mips->lo, &result, 8); + mips->lo = (u32)result; + mips->hi = (u32)(result >> 32); break; } case IROp::MaddU: { - s64 result; - memcpy(&result, &mips->lo, 8); + s64 result = (s64)((u64)mips->lo | ((u64)mips->hi << 32)); result += (u64)mips->r[inst->src1] * (u64)mips->r[inst->src2]; - memcpy(&mips->lo, &result, 8); + mips->lo = (u32)result; + mips->hi = (u32)(result >> 32); break; } case IROp::Msub: { - s64 result; - memcpy(&result, &mips->lo, 8); + s64 result = (s64)((u64)mips->lo | ((u64)mips->hi << 32)); result -= (s64)(s32)mips->r[inst->src1] * (s64)(s32)mips->r[inst->src2]; - memcpy(&mips->lo, &result, 8); + mips->lo = (u32)result; + mips->hi = (u32)(result >> 32); break; } case IROp::MsubU: { - s64 result; - memcpy(&result, &mips->lo, 8); + s64 result = (s64)((u64)mips->lo | ((u64)mips->hi << 32)); result -= (u64)mips->r[inst->src1] * (u64)mips->r[inst->src2]; - memcpy(&mips->lo, &result, 8); + mips->lo = (u32)result; + mips->hi = (u32)(result >> 32); break; } diff --git a/Core/MemMap.h b/Core/MemMap.h index 5c41f1e68381..374706f2c0f4 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -189,9 +189,9 @@ inline u32 ReadUnchecked_U32(const u32 address) { inline float ReadUnchecked_Float(const u32 address) { #ifdef MASKED_PSP_MEMORY - return *(float *)(base + (address & MEMVIEW32_MASK)); + return *(float_le *)(base + (address & MEMVIEW32_MASK)); #else - return *(float *)(base + address); + return *(float_le *)(base + address); #endif } @@ -221,9 +221,9 @@ inline void WriteUnchecked_U32(u32 data, u32 address) { inline void WriteUnchecked_Float(float data, u32 address) { #ifdef MASKED_PSP_MEMORY - *(float *)(base + (address & MEMVIEW32_MASK)) = data; + *(float_le *)(base + (address & MEMVIEW32_MASK)) = data; #else - *(float *)(base + address) = data; + *(float_le *)(base + address) = data; #endif }