From b9b591bf02c2f099907091358d95e807bcb5f57c Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 20 Jun 2019 04:32:19 +0300 Subject: [PATCH] Fix SPU Loop Detection --- rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp | 9 +++++++++ rpcs3/Emu/Cell/SPURecompiler.cpp | 7 +++++++ rpcs3/Emu/Cell/SPUThread.cpp | 3 +++ 3 files changed, 19 insertions(+) diff --git a/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp b/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp index ba40f4894f..bf5c4485b8 100644 --- a/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp @@ -1534,8 +1534,17 @@ void spu_recompiler::RDCH(spu_opcode_t op) const u32 out = _spu->ch_dec_value - static_cast(get_timebased_time() - _spu->ch_dec_start_timestamp); if (out > 1500) + { + _spu->state += cpu_flag::wait; std::this_thread::yield(); + if (_spu->test_stopped()) + { + _spu->pc += 4; + spu_runtime::g_escape(_spu); + } + } + *_res = v128::from32r(out); }; diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 41b8267d6c..a20c95597a 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -5200,7 +5200,14 @@ public: if (res > 1500 && g_cfg.core.spu_loop_detection) { + _spu->state += cpu_flag::wait; std::this_thread::yield(); + + if (_spu->test_stopped()) + { + _spu->pc += 4; + spu_runtime::g_escape(_spu); + } } return res; diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index df632ed807..2cc406010b 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -2335,7 +2335,10 @@ s64 spu_thread::get_ch_value(u32 ch) //Polling: We might as well hint to the scheduler to slot in another thread since this one is counting down if (g_cfg.core.spu_loop_detection && out > spu::scheduler::native_jiffy_duration_us) + { + state += cpu_flag::wait; std::this_thread::yield(); + } return out; }