Skip to content

Commit

Permalink
Help compiler generate some better Unpack code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Jul 16, 2024
1 parent f4b3d75 commit 3303a20
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
8 changes: 3 additions & 5 deletions Source/ee/Vif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,10 @@ void CVif::Cmd_UNPACK(StreamType& stream, CODE nCommand, uint32 nDstAddr)
((*this).*(unpackFct))(stream, nCommand, nDstAddr);
}

uint32 CVif::GetMaskOp(unsigned int row, unsigned int col) const
uint32 CVif::GetColMaskOp(unsigned int col) const
{
if(col > 3) col = 3;
assert(row < 4);
unsigned int index = (col * 4) + row;
return (m_MASK >> (index * 2)) & 0x03;
assert(col < 4);
return (m_MASK >> (col * 8)) & 0xFF;
}

void CVif::PrepareMicroProgram()
Expand Down
66 changes: 37 additions & 29 deletions Source/ee/Vif.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class CVif
void Cmd_STCOL(StreamType&, CODE);
void Cmd_STMASK(StreamType&, CODE);

inline uint32 GetMaskOp(unsigned int, unsigned int) const;
inline uint32 GetColMaskOp(unsigned int) const;

inline bool Unpack_S32(StreamType& stream, uint128& result)
{
Expand Down Expand Up @@ -577,41 +577,49 @@ class CVif
if(mustWrite)
{
auto dst = reinterpret_cast<uint128*>(vuMem + nDstAddr);
uint32 col = (m_writeTick > 3) ? 3 : m_writeTick;
uint32 colMask = useMask ? GetColMaskOp(col) : 0;

for(unsigned int i = 0; i < 4; i++)
if((colMask == 0) && (mode == 0))
{
uint32 maskOp = useMask ? GetMaskOp(i, m_writeTick) : MASK_DATA;

if(maskOp == MASK_DATA)
(*dst) = writeValue;
}
else
{
for(unsigned int i = 0; i < 4; i++)
{
if(mode == MODE_OFFSET)
uint32 maskOp = useMask ? (colMask >> (i * 2)) & 0x3 : MASK_DATA;

if(maskOp == MASK_DATA)
{
writeValue.nV[i] += m_R[i];
if(mode == MODE_OFFSET)
{
writeValue.nV[i] += m_R[i];
}
else if(mode == MODE_DIFFERENCE)
{
writeValue.nV[i] += m_R[i];
m_R[i] = writeValue.nV[i];
}

dst->nV[i] = writeValue.nV[i];
}
else if(mode == MODE_DIFFERENCE)
else if(maskOp == MASK_ROW)
{
writeValue.nV[i] += m_R[i];
m_R[i] = writeValue.nV[i];
dst->nV[i] = m_R[i];
}
else if(maskOp == MASK_COL)
{
dst->nV[i] = m_C[col];
}
else if(maskOp == MASK_MASK)
{
//Don't write anything
}
else
{
assert(0);
}

dst->nV[i] = writeValue.nV[i];
}
else if(maskOp == MASK_ROW)
{
dst->nV[i] = m_R[i];
}
else if(maskOp == MASK_COL)
{
int index = (m_writeTick > 3) ? 3 : m_writeTick;
dst->nV[i] = m_C[index];
}
else if(maskOp == MASK_MASK)
{
//Don't write anything
}
else
{
assert(0);
}
}

Expand Down

0 comments on commit 3303a20

Please sign in to comment.