From 86702186f28770daf215737b89e7ba82e8fcc640 Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 18 Aug 2022 16:10:24 +0300 Subject: [PATCH] PPU: Detect lwmutex reservation pattern and optimize it --- rpcs3/Emu/Cell/PPUThread.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index a8b3ed69a0..b15b06f8a5 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -2640,7 +2640,15 @@ static bool ppu_store_reservation(ppu_thread& ppu, u32 addr, u64 reg_value) return false; }()) { - res.notify_all(-128); + // Test a common pattern in lwmutex + constexpr u64 mutex_free = u64{static_cast(0 - 1)} << 32; + const bool may_be_lwmutex_related = sizeof(T) == 8 ? + (new_data == mutex_free && old_data == u64{ppu.id} << 32) : (old_data == mutex_free && new_data == u64{ppu.id} << 32); + + if (!may_be_lwmutex_related) + { + res.notify_all(-128); + } if (addr == ppu.last_faddr) {