From 12bfc7d56a045cdc87e2b7a86a6ccb2e0b66e87e Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:06:56 +0300 Subject: [PATCH] SPU/Debugger: Use bitset for breakpoints --- rpcs3/Emu/Cell/SPUThread.cpp | 5 ++++- rpcs3/Emu/Cell/SPUThread.h | 2 +- rpcs3/rpcs3qt/breakpoint_list.cpp | 4 +++- rpcs3/rpcs3qt/debugger_list.cpp | 13 +++++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 65dbc1dcfb..725794b6e3 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1839,7 +1839,10 @@ void spu_thread::cpu_work() if (has_active_local_bps) { - if (local_breakpoints[pc / 4]) + const u32 pos_at = pc / 4; + const u32 pos_bit = 1u << (pos_at % 8); + + if (local_breakpoints[pos_at] & pos_bit) { // Ignore repeatations until a different instruction is issued if (pc != current_bp_pc) diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index 24914f7075..82cf4bc189 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -816,7 +816,7 @@ public: atomic_t debugger_mode{}; // PC-based breakpoint list - std::array, SPU_LS_SIZE / 4> local_breakpoints{}; + std::array, SPU_LS_SIZE / 4 / 8> local_breakpoints{}; atomic_t has_active_local_bps = false; u32 current_bp_pc = umax; bool stop_flag_removal_protection = false; diff --git a/rpcs3/rpcs3qt/breakpoint_list.cpp b/rpcs3/rpcs3qt/breakpoint_list.cpp index 008ecc4df1..2447e91e03 100644 --- a/rpcs3/rpcs3qt/breakpoint_list.cpp +++ b/rpcs3/rpcs3qt/breakpoint_list.cpp @@ -125,8 +125,10 @@ void breakpoint_list::HandleBreakpointRequest(u32 loc, bool only_add) const auto spu = static_cast(m_cpu); auto& list = spu->local_breakpoints; + const u32 pos_at = loc / 4; + const u32 pos_bit = 1u << (pos_at % 8); - if (list[loc / 4].test_and_invert()) + if (list[pos_at / 8].fetch_xor(pos_bit) & pos_bit) { if (std::none_of(list.begin(), list.end(), [](auto& val){ return val.load(); })) { diff --git a/rpcs3/rpcs3qt/debugger_list.cpp b/rpcs3/rpcs3qt/debugger_list.cpp index 002ae1e0bb..25b68f27a9 100644 --- a/rpcs3/rpcs3qt/debugger_list.cpp +++ b/rpcs3/rpcs3qt/debugger_list.cpp @@ -142,8 +142,17 @@ void debugger_list::ShowAddress(u32 addr, bool select_addr, bool direct) { switch (m_cpu ? m_cpu->id_type() : 0) { - case 1: return m_ppu_breakpoint_handler->HasBreakpoint(pc); - case 2: return (*spu_bps_list)[pc / 4].load(); + case 1: + { + return m_ppu_breakpoint_handler->HasBreakpoint(pc); + } + case 2: + { + const u32 pos_at = pc / 4; + const u32 pos_bit = 1u << (pos_at % 8); + + return !!((*spu_bps_list)[pos_at] & pos_bit); + } default: return false; } };