Skip to content

Commit

Permalink
fix IR interpreter on big-endian machines.
Browse files Browse the repository at this point in the history
  • Loading branch information
aliaspider committed May 5, 2018
1 parent 3ed4294 commit a3bfe19
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
20 changes: 10 additions & 10 deletions Core/MIPS/IR/IRInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,45 +618,45 @@ 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);
memcpy(&mips->loHi, &result, 8);
break;
}
case IROp::MultU:
{
u64 result = (u64)mips->r[inst->src1] * (u64)mips->r[inst->src2];
memcpy(&mips->lo, &result, 8);
memcpy(&mips->loHi, &result, 8);
break;
}
case IROp::Madd:
{
s64 result;
memcpy(&result, &mips->lo, 8);
memcpy(&result, &mips->loHi, 8);
result += (s64)(s32)mips->r[inst->src1] * (s64)(s32)mips->r[inst->src2];
memcpy(&mips->lo, &result, 8);
memcpy(&mips->loHi, &result, 8);
break;
}
case IROp::MaddU:
{
s64 result;
memcpy(&result, &mips->lo, 8);
memcpy(&result, &mips->loHi, 8);
result += (u64)mips->r[inst->src1] * (u64)mips->r[inst->src2];
memcpy(&mips->lo, &result, 8);
memcpy(&mips->loHi, &result, 8);
break;
}
case IROp::Msub:
{
s64 result;
memcpy(&result, &mips->lo, 8);
memcpy(&result, &mips->loHi, 8);
result -= (s64)(s32)mips->r[inst->src1] * (s64)(s32)mips->r[inst->src2];
memcpy(&mips->lo, &result, 8);
memcpy(&mips->loHi, &result, 8);
break;
}
case IROp::MsubU:
{
s64 result;
memcpy(&result, &mips->lo, 8);
memcpy(&result, &mips->loHi, 8);
result -= (u64)mips->r[inst->src1] * (u64)mips->r[inst->src2];
memcpy(&mips->lo, &result, 8);
memcpy(&mips->loHi, &result, 8);
break;
}

Expand Down
17 changes: 15 additions & 2 deletions Core/MIPS/MIPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "util/random/rng.h"
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Swap.h"
// #include "Core/CoreParameter.h"
#include "Core/Opcode.h"

Expand Down Expand Up @@ -210,8 +211,20 @@ class MIPSState
struct {
u32 pc; //241

u32 lo; //242
u32 hi; //243
union {
#ifdef COMMON_BIG_ENDIAN
struct {
u32 hi; //242
u32 lo; //243
};
#else
struct {
u32 lo; //242
u32 hi; //243
};
#endif
u64 loHi; //242
};

u32 fcr31; //244 fpu control register
u32 fpcond; //245 cache the cond flag of fcr31 (& 1 << 23)
Expand Down
8 changes: 4 additions & 4 deletions Core/MemMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a3bfe19

Please sign in to comment.