Skip to content

Commit

Permalink
Backport 3DS DynaRec improvements. (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW authored Dec 11, 2020
1 parent ac9d41a commit bbdd2e2
Show file tree
Hide file tree
Showing 14 changed files with 2,788 additions and 1,129 deletions.
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set (BUILD ${CONFIG_FILES} ${CORE_FILES} ${DEBUG_FILES} ${DYNAREC_FILES} ${GRAPH
# Vita
set (VITA_MAIN_FILES SysVita/main.cpp)
set (VITA_DEBUG_FILES SysVita/Debug/DaedalusAssertVita.cpp SysVita/Debug/DBGConsoleVita.cpp )
set (VITA_DYNAREC_FILES SysVita/DynaRec/DynarecStubARM.S SysVita/DynaRec/CodeGeneratorARM.cpp SysVita/DynaRec/CodeBufferManagerARM.cpp SysVita/DynaRec/AssemblyWriterARM.cpp SysVita/DynaRec/AssemblyUtilsARM.cpp)
set (VITA_DYNAREC_FILES SysVita/DynaRec/DynarecStubARM.S SysVita/DynaRec/CodeGeneratorARM.cpp SysVita/DynaRec/CodeBufferManagerARM.cpp SysVita/DynaRec/AssemblyWriterARM.cpp SysVita/DynaRec/AssemblyUtilsARM.cpp SysVita/DynaRec/N64RegisterCacheARM.cpp)
set (VITA_GRAPHICS_FILES SysVita/Graphics/GraphicsContextVita.cpp SysVita/Graphics/NativeTextureVita.cpp)
set (VITA_HLEGRAPHICS_FILES SysVita/HLEGraphics/GraphicsPluginVita.cpp SysVita/HLEGraphics/RendererLegacy.cpp SysVita/HLEGraphics/RendererModern.cpp SysVita/HLEGraphics/ColourAdjuster.cpp SysVita/HLEGraphics/BlendModes.cpp SysVita/HLEGraphics/Combiner/BlendConstant.cpp SysVita/HLEGraphics/Combiner/CombinerExpression.cpp SysVita/HLEGraphics/Combiner/CombinerTree.cpp SysVita/HLEGraphics/Combiner/RenderSettings.cpp)
set (VITA_HLEAUDIO_FILES SysVita/HLEAudio/AudioPluginVita.cpp SysVita/HLEAudio/AudioOutput.cpp)
Expand Down
5 changes: 1 addition & 4 deletions Source/DynaRec/AssemblyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ class CJumpLocation
public:
CJumpLocation () : mpLocation( nullptr ) {}

explicit CJumpLocation( void * p_location )
: mpLocation( p_location )
{
}
explicit CJumpLocation( void * p_location ) : mpLocation( p_location ) {}

bool IsSet() const { return mpLocation != nullptr; }
s32 GetOffset( const CCodeLabel & label ) const { return label.GetTargetU8P() - GetTargetU8P(); }
Expand Down
3 changes: 1 addition & 2 deletions Source/DynaRec/CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CCodeGenerator
virtual ~CCodeGenerator() {}

virtual void Initialise( u32 entry_address, u32 exit_address, u32 * hit_counter, const void * p_base, const SRegisterUsageInfo & register_usage ) = 0;
virtual void Finalise( ExceptionHandlerFn p_exception_handler_fn, const std::vector< CJumpLocation > & exception_handler_jumps ) = 0;
virtual void Finalise( ExceptionHandlerFn p_exception_handler_fn, const std::vector< CJumpLocation > & exception_handler_jumps, const std::vector<RegisterSnapshotHandle> & exception_handler_snapshots ) = 0;


virtual void UpdateRegisterCaching( u32 instruction_idx ) = 0;
Expand All @@ -67,7 +67,6 @@ class CCodeGenerator

virtual void GenerateBranchHandler( CJumpLocation branch_handler_jump, RegisterSnapshotHandle snapshot ) = 0;

virtual CJumpLocation GenerateInterpOpCode(const STraceEntry& ti, bool branch_delay_slot, const SBranchDetails * p_branch, CJumpLocation * p_branch_jump) = 0;
virtual CJumpLocation GenerateOpCode(const STraceEntry& ti, bool branch_delay_slot, const SBranchDetails * p_branch, CJumpLocation * p_branch_jump) = 0;
virtual CJumpLocation ExecuteNativeFunction( CCodeLabel speed_hack, bool check_return = false ) = 0;
};
Expand Down
29 changes: 12 additions & 17 deletions Source/DynaRec/Fragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Utility/Profiler.h"
#include "Utility/Synchroniser.h"

#include "Config/ConfigOptions.h"

#include "OSHLE/ultra_R4300.h"
#include "OSHLE/patch.h"

Expand Down Expand Up @@ -188,7 +186,6 @@ void CFragment::Execute()
#else
const void * p( g_pu8RamBase_8000 );
u32 upper( 0x80000000 + gRamSize );

_EnterDynaRec( mEntryPoint.GetTarget(), &gCPUState, p, upper );
#endif // FRAGMENT_SIMULATE_EXECUTION

Expand Down Expand Up @@ -615,6 +612,7 @@ void CFragment::Assemble( CCodeBufferManager * p_manager,
// Keep executing ops until we take a branch
//
std::vector< CJumpLocation > exception_handler_jumps;
std::vector< RegisterSnapshotHandle > exception_handler_snapshots;
std::vector< SBranchHandlerInfo > branch_handler_info( branch_details.size() );
// bool checked_cop1_usable( false );

Expand Down Expand Up @@ -710,16 +708,14 @@ void CFragment::Assemble( CCodeBufferManager * p_manager,
CJumpLocation branch_jump( nullptr );
//PSP, We handle exceptions directly with _ReturnFromDynaRecIfStuffToDo
#ifdef DAEDALUS_PSP
if (gUseCachedInterpreter) p_generator->GenerateInterpOpCode( ti, ti.BranchDelaySlot, p_branch, &branch_jump);
else p_generator->GenerateOpCode( ti, ti.BranchDelaySlot, p_branch, &branch_jump);
p_generator->GenerateOpCode( ti, ti.BranchDelaySlot, p_branch, &branch_jump);
#else
CJumpLocation exception_handler_jump;
if (gUseCachedInterpreter) exception_handler_jump = p_generator->GenerateInterpOpCode( ti, ti.BranchDelaySlot, p_branch, &branch_jump);
else exception_handler_jump = p_generator->GenerateOpCode( ti, ti.BranchDelaySlot, p_branch, &branch_jump);
CJumpLocation exception_handler_jump( p_generator->GenerateOpCode( ti, ti.BranchDelaySlot, p_branch, &branch_jump) );

if( exception_handler_jump.IsSet() )
{
exception_handler_jumps.push_back( exception_handler_jump );
exception_handler_snapshots.push_back(p_generator->GetRegisterSnapshot());
}
#endif

Expand Down Expand Up @@ -786,16 +782,14 @@ void CFragment::Assemble( CCodeBufferManager * p_manager,
*/
//PSP, We handle exceptions directly with _ReturnFromDynaRecIfStuffToDo
#ifdef DAEDALUS_PSP
if (gUseCachedInterpreter) p_generator->GenerateInterpOpCode( ti, true, nullptr, nullptr);
else p_generator->GenerateOpCode( ti, true, nullptr, nullptr);
p_generator->GenerateOpCode( ti, true, nullptr, nullptr);
#else
CJumpLocation exception_handler_jump;
if (gUseCachedInterpreter) exception_handler_jump = p_generator->GenerateInterpOpCode( ti, true, nullptr, nullptr);
else exception_handler_jump = p_generator->GenerateOpCode( ti, true, nullptr, nullptr);

CJumpLocation exception_handler_jump( p_generator->GenerateOpCode( ti, true, nullptr, nullptr) );

if( exception_handler_jump.IsSet() )
{
exception_handler_jumps.push_back( exception_handler_jump );
exception_handler_jumps.push_back(exception_handler_jump);
exception_handler_snapshots.push_back(p_generator->GetRegisterSnapshot());
}
#endif
num_instructions_executed++;
Expand Down Expand Up @@ -847,7 +841,7 @@ void CFragment::Assemble( CCodeBufferManager * p_manager,
}
}

p_generator->Finalise( HandleException, exception_handler_jumps );
p_generator->Finalise( HandleException, exception_handler_jumps, exception_handler_snapshots );

mFragmentFunctionLength = p_manager->FinaliseCurrentBlock();
mOutputLength = mFragmentFunctionLength - ADDITIONAL_OUTPUT_BYTES;
Expand All @@ -862,6 +856,7 @@ void CFragment::Assemble( CCodeBufferManager * p_manager,
void CFragment::Assemble( CCodeBufferManager * p_manager, CCodeLabel function_ptr)
{
std::vector< CJumpLocation > exception_handler_jumps;
std::vector< RegisterSnapshotHandle> exception_handler_snapshots;
SRegisterUsageInfo register_usage;

CCodeGenerator *p_generator = p_manager->StartNewBlock();
Expand All @@ -879,7 +874,7 @@ void CFragment::Assemble( CCodeBufferManager * p_manager, CCodeLabel function_pt
AssemblyUtils::PatchJumpLong(jump, p_generator->GetCurrentLocation());
p_generator->GenerateEretExitCode(100, mpIndirectExitMap);

p_generator->Finalise( HandleException, exception_handler_jumps );
p_generator->Finalise( HandleException, exception_handler_jumps, exception_handler_snapshots );
mFragmentFunctionLength = p_manager->FinaliseCurrentBlock();
mOutputLength = mFragmentFunctionLength - ADDITIONAL_OUTPUT_BYTES;

Expand Down
16 changes: 5 additions & 11 deletions Source/SysVita/DynaRec/AssemblyUtilsARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ bool PatchJumpLong( CJumpLocation jump, CCodeLabel target )

u32 address = target.GetTargetU32();

#ifdef DYNAREC_ARMV7
p_jump_addr[0] = (p_jump_addr[0] & 0xFFF0F000) | ((address & 0xf000) << 4) | (address & 0x0fff);
address = address >> 16;
p_jump_addr[1] = (p_jump_addr[1] & 0xFFF0F000) | ((address & 0xf000) << 4) | (address & 0x0fff);
#else
p_jump_addr[0] = (p_jump_addr[0] & ~0xFF) | (address & 0xFF);
p_jump_addr[1] = (p_jump_addr[1] & ~0xFF) | ((address >> 8) & 0xFF);
p_jump_addr[2] = (p_jump_addr[2] & ~0xFF) | ((address >> 16) & 0xFF);
p_jump_addr[3] = (p_jump_addr[3] & ~0xFF) | ((address >> 24) & 0xFF);
#endif
s32 offset = jump.GetOffset(target) - 8;

offset >>= 2;
p_jump_addr[0] = (p_jump_addr[0] &0xFF000000)| (offset & 0xFFFFFF);

// All jumps are 32 bit offsets, and so always succeed.
return true;
Expand All @@ -56,7 +50,7 @@ bool PatchJumpLongAndFlush( CJumpLocation jump, CCodeLabel target )
{
PatchJumpLong( jump, target );

_DaedalusICacheInvalidate( jump.GetTargetU8P(), 8 );
_DaedalusICacheInvalidate( jump.GetTargetU8P(), 4 );

return true;
}
Expand Down
Loading

0 comments on commit bbdd2e2

Please sign in to comment.