Skip to content

Commit

Permalink
Merge pull request #56 from howard0su/dynarec_norm
Browse files Browse the repository at this point in the history
De-duplicate register cache code
  • Loading branch information
wally4000 authored Dec 16, 2023
2 parents df2fc99 + 8ad213b commit 299bad4
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 318 deletions.
4 changes: 3 additions & 1 deletion Source/DynaRec/ARM/CodeGeneratorARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "AssemblyWriterARM.h"
#include "DynarecTargetARM.h"
#include "DynaRec/TraceRecorder.h"
#include "N64RegisterCacheARM.h"
#include "DynaRec/N64RegisterCache.h"
#include <stack>

using CN64RegisterCacheARM = CN64RegisterCache<EArmReg>;

// XXXX For GenerateCompare_S/D
#define FLAG_SWAP 0x100
#define FLAG_C_LT (0x41) // jne- le
Expand Down
4 changes: 3 additions & 1 deletion Source/DynaRec/ARM/DynarecTargetARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ enum EArmCond
};

// Return true if this register dont need sign extension //Corn
inline bool N64Reg_DontNeedSign( EN64Reg n64_reg ) { return (0x30000001 >> n64_reg) & 1;}
inline bool N64Reg_DontNeedSign( EN64Reg n64_reg ) { return (0x30000001 >> n64_reg) & 1;}

inline bool Reg_IsTemporary(EArmReg reg) { return false; }
63 changes: 0 additions & 63 deletions Source/DynaRec/ARM/N64RegisterCacheARM.cpp

This file was deleted.

173 changes: 0 additions & 173 deletions Source/DynaRec/ARM/N64RegisterCacheARM.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include <stdlib.h>

#include "DynarecTargetPSP.h"

//*************************************************************************************
//
//*************************************************************************************
class CN64RegisterCachePSP
template<typename NativeReg> class CN64RegisterCache
{
public:
CN64RegisterCachePSP();
CN64RegisterCache() {
Reset();
}

void Reset()
{
for (u32 lo_hi_idx{}; lo_hi_idx < 2; ++lo_hi_idx)
{
for (u32 i{}; i < NUM_N64_REGS; ++i)
{
mRegisterCacheInfo[i][lo_hi_idx].NativeRegister = (NativeReg)-1;
mRegisterCacheInfo[i][lo_hi_idx].Valid = false;
mRegisterCacheInfo[i][lo_hi_idx].Dirty = false;
mRegisterCacheInfo[i][lo_hi_idx].Known = false;
}
}

void Reset();
for (u32 i{}; i < NUM_N64_FP_REGS; ++i)
{
mFPRegisterCacheInfo[i].Valid = false;
mFPRegisterCacheInfo[i].Dirty = false;
mFPRegisterCacheInfo[i].Sim = false;
}
}

inline void SetCachedReg( EN64Reg n64_reg, u32 lo_hi_idx, EPspReg psp_reg )
inline void SetCachedReg( EN64Reg n64_reg, u32 lo_hi_idx, NativeReg psp_reg )
{
mRegisterCacheInfo[ n64_reg ][ lo_hi_idx ].PspRegister = psp_reg;
mRegisterCacheInfo[ n64_reg ][ lo_hi_idx ].NativeRegister = psp_reg;
}

inline bool IsCached( EN64Reg reg, u32 lo_hi_idx ) const
{
return mRegisterCacheInfo[ reg ][ lo_hi_idx ].PspRegister != PspReg_R0;
return mRegisterCacheInfo[ reg ][ lo_hi_idx ].NativeRegister != (NativeReg)-1;
}

inline bool IsValid( EN64Reg reg, u32 lo_hi_idx ) const
Expand Down Expand Up @@ -74,18 +94,18 @@ class CN64RegisterCachePSP
{
if( IsCached( reg, lo_hi_idx ) )
{
return PspReg_IsTemporary( mRegisterCacheInfo[ reg ][ lo_hi_idx ].PspRegister );
return Reg_IsTemporary( mRegisterCacheInfo[ reg ][ lo_hi_idx ].NativeRegister );
}

return false;
}

inline EPspReg GetCachedReg( EN64Reg reg, u32 lo_hi_idx ) const
inline NativeReg GetCachedReg( EN64Reg reg, u32 lo_hi_idx ) const
{
#ifdef DAEDALUS_ENABLE_ASSERTS
DAEDALUS_ASSERT( IsCached( reg, lo_hi_idx ), "Trying to retreive an uncached register" );
#endif
return mRegisterCacheInfo[ reg ][ lo_hi_idx ].PspRegister;
return mRegisterCacheInfo[ reg ][ lo_hi_idx ].NativeRegister;
}

inline void MarkAsValid( EN64Reg reg, u32 lo_hi_idx, bool valid )
Expand Down Expand Up @@ -159,14 +179,24 @@ class CN64RegisterCachePSP
mFPRegisterCacheInfo[ reg ].Sim = Sim;
}

void ClearCachedReg( EN64Reg n64_reg, u32 lo_hi_idx );
void ClearCachedReg(EN64Reg n64_reg, u32 lo_hi_idx)
{
#ifdef DAEDALUS_ENABLE_ASSERTS
DAEDALUS_ASSERT(IsCached(n64_reg, lo_hi_idx), "This register is not currently cached");
DAEDALUS_ASSERT(!IsDirty(n64_reg, lo_hi_idx), "This register is being cleared while still dirty");
#endif
mRegisterCacheInfo[n64_reg][lo_hi_idx].NativeRegister = (NativeReg)-1;
mRegisterCacheInfo[n64_reg][lo_hi_idx].Valid = false;
mRegisterCacheInfo[n64_reg][lo_hi_idx].Dirty = false;
mRegisterCacheInfo[n64_reg][lo_hi_idx].Known = false;
}

private:
private:

struct RegisterCacheInfoPSP
{
REG32 KnownValue; // The contents (if known)
EPspReg PspRegister; // If cached, this is the psp register we're using
NativeReg NativeRegister; // If cached, this is the psp register we're using
bool Valid; // Is the contents of the register valid?
bool Dirty; // Is the contents of the register modified?
bool Known; // Is the contents of the known?
Expand Down
1 change: 0 additions & 1 deletion Source/DynaRec/mips/CodeGeneratorPSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Base/MathUtil.h"
#include "Ultra/ultra_R4300.h"
#include "CodeGeneratorPSP.h"
#include "N64RegisterCachePSP.h"
#include "Base/Macros.h"
#include "Core/PrintOpCode.h"
#include "Utility/Profiler.h"
Expand Down
4 changes: 3 additions & 1 deletion Source/DynaRec/mips/CodeGeneratorPSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "DynaRec/CodeGenerator.h"
#include "AssemblyWriterPSP.h"
#include "N64RegisterCachePSP.h"
#include "DynarecTargetPSP.h"
#include "DynaRec/N64RegisterCache.h"
#include <stack>

class CAssemblyBuffer;

using CN64RegisterCachePSP = CN64RegisterCache<EPspReg>;

class CCodeGeneratorPSP : public CCodeGenerator, public CAssemblyWriterPSP
{
Expand Down
2 changes: 1 addition & 1 deletion Source/DynaRec/mips/DynarecTargetPSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum EPspFloatReg
};

// Return true if this register is temporary (i.e. not saved across function calls)
inline bool PspReg_IsTemporary( EPspReg psp_reg ) { return (0xB300FFFF >> psp_reg) & 1;}
inline bool Reg_IsTemporary( EPspReg psp_reg ) { return (0xB300FFFF >> psp_reg) & 1;}

// Return true if this register dont need sign extension //Corn
inline bool N64Reg_DontNeedSign( EN64Reg n64_reg ) { return (0x30000001 >> n64_reg) & 1;}
Expand Down
Loading

0 comments on commit 299bad4

Please sign in to comment.