JIT optimizations and refactoring (#675)

* CPU/Recompiler: Use rel32 call where possible for no-args

* JitCodeBuffer: Support using preallocated buffer

* CPU/Recompiler/AArch64: Use bl instead of blr for short branches

* CPU/CodeCache: Allocate recompiler buffer in program space

This means we don't need 64-bit moves for every call out of the
recompiler.

* GTE: Don't store as u16 and load as u32

* CPU/Recompiler: Add methods to emit global load/stores

* GTE: Convert class to namespace

* CPU/Recompiler: Call GTE functions directly

* Settings: Turn into a global variable

* GPU: Replace local pointers with global

* InterruptController: Turn into a global pointer

* System: Replace local pointers with global

* Timers: Turn into a global instance

* DMA: Turn into a global instance

* SPU: Turn into a global instance

* CDROM: Turn into a global instance

* MDEC: Turn into a global instance

* Pad: Turn into a global instance

* SIO: Turn into a global instance

* CDROM: Move audio FIFO to the heap

* CPU/Recompiler: Drop ASMFunctions

No longer needed since we have code in the same 4GB window.

* CPUCodeCache: Turn class into namespace

* Bus: Local pointer -> global pointers

* CPU: Turn class into namespace

* Bus: Turn into namespace

* GTE: Store registers in CPU state struct

Allows relative addressing on ARM.

* CPU/Recompiler: Align code storage to page size

* CPU/Recompiler: Fix relative branches on A64

* HostInterface: Local references to global

* System: Turn into a namespace, move events out

* Add guard pages

* Android: Fix build
This commit is contained in:
Connor McLaughlin
2020-07-31 17:09:18 +10:00
committed by GitHub
parent 1f9fc6ab74
commit b6f871d2b9
88 changed files with 4993 additions and 5045 deletions

View File

@ -275,23 +275,31 @@ static std::array<CommandInfo, 255> s_command_info = {{
0 // Unknown
}};
CDROM g_cdrom;
CDROM::CDROM() = default;
CDROM::~CDROM() = default;
void CDROM::Initialize(System* system, DMA* dma, InterruptController* interrupt_controller, SPU* spu)
void CDROM::Initialize()
{
m_system = system;
m_dma = dma;
m_interrupt_controller = interrupt_controller;
m_spu = spu;
m_command_event =
m_system->CreateTimingEvent("CDROM Command Event", 1, 1, std::bind(&CDROM::ExecuteCommand, this), false);
m_drive_event = m_system->CreateTimingEvent("CDROM Drive Event", 1, 1,
std::bind(&CDROM::ExecuteDrive, this, std::placeholders::_2), false);
TimingEvents::CreateTimingEvent("CDROM Command Event", 1, 1, std::bind(&CDROM::ExecuteCommand, this), false);
m_drive_event = TimingEvents::CreateTimingEvent("CDROM Drive Event", 1, 1,
std::bind(&CDROM::ExecuteDrive, this, std::placeholders::_2), false);
if (m_system->GetSettings().cdrom_read_thread)
if (g_settings.cdrom_read_thread)
m_reader.StartThread();
Reset();
}
void CDROM::Shutdown()
{
m_command_event.reset();
m_drive_event.reset();
m_reader.StopThread();
m_reader.RemoveMedia();
}
void CDROM::Reset()
@ -438,7 +446,7 @@ void CDROM::InsertMedia(std::unique_ptr<CDImage> media)
// set the region from the system area of the disc
m_disc_region = GameList::GetRegionForImage(media.get());
Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s", Settings::GetDiscRegionName(m_disc_region),
Settings::GetConsoleRegionName(m_system->GetRegion()));
Settings::GetConsoleRegionName(System::GetRegion()));
// motor automatically spins up
if (m_drive_state != DriveState::ShellOpening)
@ -787,7 +795,7 @@ void CDROM::UpdateStatusRegister()
m_status.DRQSTS = !m_data_fifo.IsEmpty();
m_status.BUSYSTS = HasPendingCommand();
m_dma->SetRequest(DMA::Channel::CDROM, m_status.DRQSTS);
g_dma.SetRequest(DMA::Channel::CDROM, m_status.DRQSTS);
}
void CDROM::UpdateInterruptRequest()
@ -795,7 +803,7 @@ void CDROM::UpdateInterruptRequest()
if ((m_interrupt_flag_register & m_interrupt_enable_register) == 0)
return;
m_interrupt_controller->InterruptRequest(InterruptController::IRQ::CDROM);
g_interrupt_controller.InterruptRequest(InterruptController::IRQ::CDROM);
}
TickCount CDROM::GetAckDelayForCommand(Command command)
@ -1421,7 +1429,7 @@ void CDROM::ExecuteTestCommand(u8 subcommand)
{
Log_DebugPrintf("Get CDROM region ID string");
switch (m_system->GetRegion())
switch (System::GetRegion())
{
case ConsoleRegion::NTSC_J:
{
@ -1860,9 +1868,9 @@ void CDROM::DoIDRead()
m_current_lba = 0;
m_reader.QueueReadSector(0);
if (m_system->GetSettings().cdrom_region_check &&
if (g_settings.cdrom_region_check &&
(m_disc_region == DiscRegion::Other ||
m_system->GetRegion() != System::GetConsoleRegionForDiscRegion(m_disc_region)))
System::GetRegion() != System::GetConsoleRegionForDiscRegion(m_disc_region)))
{
stat_byte |= STAT_ID_ERROR;
flags_byte |= (1 << 7); // Unlicensed
@ -2214,7 +2222,7 @@ void CDROM::ProcessXAADPCMSector(const u8* raw_sector, const CDImage::SubChannel
if (m_muted || m_adpcm_muted)
return;
m_spu->GeneratePendingSamples();
g_spu.GeneratePendingSamples();
if (m_last_sector_subheader.codinginfo.IsStereo())
{
@ -2282,7 +2290,7 @@ void CDROM::ProcessCDDASector(const u8* raw_sector, const CDImage::SubChannelQ&
if (m_muted)
return;
m_spu->GeneratePendingSamples();
g_spu.GeneratePendingSamples();
constexpr bool is_stereo = true;
constexpr u32 num_samples = CDImage::RAW_SECTOR_SIZE / sizeof(s16) / (is_stereo ? 2 : 1);
@ -2347,7 +2355,7 @@ void CDROM::DrawDebugWindow()
const float framebuffer_scale = ImGui::GetIO().DisplayFramebufferScale.x;
ImGui::SetNextWindowSize(ImVec2(800.0f * framebuffer_scale, 550.0f * framebuffer_scale), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("CDROM State", &m_system->GetSettings().debugging.show_cdrom_state))
if (!ImGui::Begin("CDROM State", &g_settings.debugging.show_cdrom_state))
{
ImGui::End();
return;