Skip to content

Commit

Permalink
PowerPC: Remove separate macros for paired singles
Browse files Browse the repository at this point in the history
Previously, PowerPC.h had four macros in it like so:

\#define rPS0(i) (*(double*)(&PowerPC::ppcState.ps[i][0]))
\#define rPS1(i) (*(double*)(&PowerPC::ppcState.ps[i][1]))

\#define riPS0(i) (*(u64*)(&PowerPC::ppcState.ps[i][0]))
\#define riPS1(i) (*(u64*)(&PowerPC::ppcState.ps[i][1]))

Casting between object representations like this is undefined behavior.
Given this is used heavily with the interpreter (that is, the most
accurate, but slowest CPU backend), we don't exactly want to allow
undefined behavior to creep into it.

Instead, this adds a helper struct for operating with the paired singles,
and replaces the four macros with a single macro for accessing the
paired-singles/floating-point registers.

This way, it's left up to the caller to explicitly decide how it wants to interpret
the data (and makes it more obvious where different interpretations of
the same data are occurring at, as there'll be a call to one of the
[x]AsDouble() functions).
  • Loading branch information
lioncash committed Dec 16, 2018
1 parent 2dcd058 commit 3b8ee5b
Show file tree
Hide file tree
Showing 15 changed files with 457 additions and 235 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Core/GeckoCode.cpp
Expand Up @@ -272,8 +272,8 @@ void RunCodeHandler()
// Registers FPR0->13 are volatile
for (int i = 0; i < 14; ++i)
{
PowerPC::HostWrite_U64(riPS0(i), SP + 24 + 2 * i * sizeof(u64));
PowerPC::HostWrite_U64(riPS1(i), SP + 24 + (2 * i + 1) * sizeof(u64));
PowerPC::HostWrite_U64(rPS(i).PS0AsIntegral(), SP + 24 + 2 * i * sizeof(u64));
PowerPC::HostWrite_U64(rPS(i).PS1AsIntegral(), SP + 24 + (2 * i + 1) * sizeof(u64));
}
DEBUG_LOG(ACTIONREPLAY,
"GeckoCodes: Initiating phantom branch-and-link. "
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HLE/HLE_Misc.cpp
Expand Up @@ -64,8 +64,8 @@ void GeckoReturnTrampoline()
PowerPC::ExpandCR(PowerPC::HostRead_U32(SP + 20));
for (int i = 0; i < 14; ++i)
{
riPS0(i) = PowerPC::HostRead_U64(SP + 24 + 2 * i * sizeof(u64));
riPS1(i) = PowerPC::HostRead_U64(SP + 24 + (2 * i + 1) * sizeof(u64));
rPS(i).SetBoth(PowerPC::HostRead_U64(SP + 24 + 2 * i * sizeof(u64)),
PowerPC::HostRead_U64(SP + 24 + (2 * i + 1) * sizeof(u64)));
}
}
}
2 changes: 1 addition & 1 deletion Source/Core/Core/HLE/HLE_VarArgs.cpp
Expand Up @@ -15,7 +15,7 @@ u32 HLE::SystemVABI::VAList::GetGPR(u32 gpr) const

double HLE::SystemVABI::VAList::GetFPR(u32 fpr) const
{
return rPS0(fpr);
return rPS(fpr).PS0AsDouble();
}

HLE::SystemVABI::VAListStruct::VAListStruct(u32 address)
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Expand Up @@ -88,8 +88,10 @@ static void Trace(UGeckoInstruction& inst)
std::string fregs = "";
for (int i = 0; i < 32; i++)
{
fregs += StringFromFormat("f%02d: %08" PRIx64 " %08" PRIx64 " ", i, PowerPC::ppcState.ps[i][0],
PowerPC::ppcState.ps[i][1]);
const auto& ps = PowerPC::ppcState.ps[i];

fregs += StringFromFormat("f%02d: %08" PRIx64 " %08" PRIx64 " ", i, ps.PS0AsIntegral(),
ps.PS1AsIntegral());
}

const std::string ppc_inst = Common::GekkoDisassembler::Disassemble(inst.hex, PC);
Expand Down

0 comments on commit 3b8ee5b

Please sign in to comment.