Skip to content

Commit 8bce5b0

Browse files
committed
CPU/PGXP: Make register writes more readable
1 parent 05a5828 commit 8bce5b0

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

src/core/cpu_pgxp.cpp

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ enum : u32
6161
#define SET_LOWORD(val, loword) ((static_cast<u32>(val) & 0xFFFF0000u) | static_cast<u32>(static_cast<u16>(loword)))
6262
#define SET_HIWORD(val, hiword) ((static_cast<u32>(val) & 0x0000FFFFu) | (static_cast<u32>(hiword) << 16))
6363

64+
#define PGXP_GTE_REGISTER(field) g_state.pgxp_gte[offsetof(GTE::Regs, field) / sizeof(u32)]
65+
6466
static bool ShouldSavePGXPState();
6567

6668
static double f16Sign(double val);
@@ -79,9 +81,6 @@ static PGXPValue& ValidateAndGetRtValue(Instruction instr, u32 rtVal);
7981
static PGXPValue& ValidateAndGetRsValue(Instruction instr, u32 rsVal);
8082
static void SetRtValue(Instruction instr, const PGXPValue& val);
8183
static void SetRtValue(Instruction instr, const PGXPValue& val, u32 rtVal);
82-
static PGXPValue& GetSXY0();
83-
static PGXPValue& GetSXY1();
84-
static PGXPValue& GetSXY2();
8584
static void PushScreenXYFIFO();
8685

8786
static PGXPValue* GetPtr(u32 addr);
@@ -133,6 +132,12 @@ static std::FILE* s_log;
133132

134133
void CPU::PGXP::Initialize()
135134
{
135+
// Just in case due to memory layout...
136+
static_assert(&PGXP_GTE_REGISTER(SXY0) == &g_state.pgxp_gte[12]);
137+
static_assert(&PGXP_GTE_REGISTER(SXY1) == &g_state.pgxp_gte[13]);
138+
static_assert(&PGXP_GTE_REGISTER(SXY2) == &g_state.pgxp_gte[14]);
139+
static_assert(&PGXP_GTE_REGISTER(SXYP) == &g_state.pgxp_gte[15]);
140+
136141
std::memset(g_state.pgxp_gpr, 0, sizeof(g_state.pgxp_gpr));
137142
std::memset(g_state.pgxp_cop0, 0, sizeof(g_state.pgxp_cop0));
138143
std::memset(g_state.pgxp_gte, 0, sizeof(g_state.pgxp_gte));
@@ -277,26 +282,11 @@ ALWAYS_INLINE void CPU::PGXP::SetRtValue(Instruction instr, const PGXPValue& val
277282
prtVal.value = rtVal;
278283
}
279284

280-
ALWAYS_INLINE CPU::PGXPValue& CPU::PGXP::GetSXY0()
281-
{
282-
return g_state.pgxp_gte[12];
283-
}
284-
285-
ALWAYS_INLINE CPU::PGXPValue& CPU::PGXP::GetSXY1()
286-
{
287-
return g_state.pgxp_gte[13];
288-
}
289-
290-
ALWAYS_INLINE CPU::PGXPValue& CPU::PGXP::GetSXY2()
291-
{
292-
return g_state.pgxp_gte[14];
293-
}
294-
295285
ALWAYS_INLINE void CPU::PGXP::PushScreenXYFIFO()
296286
{
297-
g_state.pgxp_gte[12] = g_state.pgxp_gte[13]; // SXY0 = SXY1
298-
g_state.pgxp_gte[13] = g_state.pgxp_gte[14]; // SXY1 = SXY2
299-
g_state.pgxp_gte[14] = g_state.pgxp_gte[15]; // SXY2 = SXYP
287+
PGXP_GTE_REGISTER(SXY0) = PGXP_GTE_REGISTER(SXY1); // SXY0 = SXY1
288+
PGXP_GTE_REGISTER(SXY1) = PGXP_GTE_REGISTER(SXY2); // SXY1 = SXY2
289+
PGXP_GTE_REGISTER(SXY2) = PGXP_GTE_REGISTER(SXYP); // SXY2 = SXYP
300290
}
301291

302292
ALWAYS_INLINE_RELEASE CPU::PGXPValue* CPU::PGXP::GetPtr(u32 addr)
@@ -498,25 +488,25 @@ void CPU::PGXP::LogValueStr(SmallStringBase& str, const char* name, u32 rval, co
498488

499489
void CPU::PGXP::GTE_RTPS(float x, float y, float z, u32 value)
500490
{
501-
PGXPValue& pvalue = g_state.pgxp_gte[15];
502-
pvalue.x = x;
503-
pvalue.y = y;
504-
pvalue.z = z;
505-
pvalue.value = value;
506-
pvalue.flags = VALID_ALL;
491+
PGXPValue& SXYP = PGXP_GTE_REGISTER(SXYP);
492+
SXYP.x = x;
493+
SXYP.y = y;
494+
SXYP.z = z;
495+
SXYP.value = value;
496+
SXYP.flags = VALID_ALL;
507497
PushScreenXYFIFO();
508498

509499
if (g_settings.gpu_pgxp_vertex_cache)
510-
CacheVertex(value, pvalue);
500+
CacheVertex(value, SXYP);
511501
}
512502

513503
bool CPU::PGXP::GTE_HasPreciseVertices(u32 sxy0, u32 sxy1, u32 sxy2)
514504
{
515-
PGXPValue& SXY0 = GetSXY0();
505+
PGXPValue& SXY0 = PGXP_GTE_REGISTER(SXY0);
516506
SXY0.Validate(sxy0);
517-
PGXPValue& SXY1 = GetSXY1();
507+
PGXPValue& SXY1 = PGXP_GTE_REGISTER(SXY1);
518508
SXY1.Validate(sxy1);
519-
PGXPValue& SXY2 = GetSXY2();
509+
PGXPValue& SXY2 = PGXP_GTE_REGISTER(SXY2);
520510
SXY2.Validate(sxy2);
521511

522512
// Don't use accurate clipping for game-constructed values, which don't have a valid Z.
@@ -525,9 +515,9 @@ bool CPU::PGXP::GTE_HasPreciseVertices(u32 sxy0, u32 sxy1, u32 sxy2)
525515

526516
float CPU::PGXP::GTE_NCLIP()
527517
{
528-
const PGXPValue& SXY0 = GetSXY0();
529-
const PGXPValue& SXY1 = GetSXY1();
530-
const PGXPValue& SXY2 = GetSXY2();
518+
const PGXPValue& SXY0 = PGXP_GTE_REGISTER(SXY0);
519+
const PGXPValue& SXY1 = PGXP_GTE_REGISTER(SXY1);
520+
const PGXPValue& SXY2 = PGXP_GTE_REGISTER(SXY2);
531521
float nclip = ((SXY0.x * SXY1.y) + (SXY1.x * SXY2.y) + (SXY2.x * SXY0.y) - (SXY0.x * SXY2.y) - (SXY1.x * SXY0.y) -
532522
(SXY2.x * SXY1.y));
533523

@@ -546,7 +536,7 @@ ALWAYS_INLINE_RELEASE void CPU::PGXP::CPU_MTC2(u32 reg, const PGXPValue& value,
546536
case 15:
547537
{
548538
// push FIFO
549-
g_state.pgxp_gte[15] = value;
539+
PGXP_GTE_REGISTER(SXYP) = value;
550540
PushScreenXYFIFO();
551541
return;
552542
}

0 commit comments

Comments
 (0)