From 45c6e938a5eee47f6e276b33463020866005d67d Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Thu, 26 Feb 2026 15:50:37 +0200 Subject: [PATCH] SPU LLVM: Expand SPU Profiling to blocks --- rpcs3/Emu/CPU/CPUThread.cpp | 6 +----- rpcs3/Emu/Cell/SPUCommonRecompiler.cpp | 4 +++- rpcs3/Emu/Cell/SPULLVMRecompiler.cpp | 8 ++++++++ rpcs3/Emu/Cell/SPUThread.cpp | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index afec56f7e1..e37e6ed0da 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -206,11 +206,7 @@ struct cpu_prof // Print only 7 hash characters out of 11 (which covers roughly 48 bits) if (type_id == 2) { - fmt::append(results, "\n\t[%s", fmt::base57(be_t{name})); - results.resize(results.size() - 4); - - // Print chunk address from lowest 16 bits - fmt::append(results, "...chunk-0x%05x]: %.4f%% (%u)", (name & 0xffff) * 4, _frac * 100., count); + fmt::append(results, "\n\t[%s]: %.4f%% (%u)", spu_block_hash{name}, _frac * 100., count); } else { diff --git a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp index b4a7945ff3..1b6003036b 100644 --- a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp @@ -7391,6 +7391,7 @@ void spu_recompiler_base::dump(const spu_program& result, std::string& out) SPUDisAsm dis_asm(cpu_disasm_mode::dump, reinterpret_cast(result.data.data()), result.lower_bound); std::string hash; + be_t hash_start{}; if (!result.data.empty()) { @@ -7401,6 +7402,7 @@ void spu_recompiler_base::dump(const spu_program& result, std::string& out) sha1_update(&ctx, reinterpret_cast(result.data.data()), result.data.size() * 4); sha1_finish(&ctx, output); fmt::append(hash, "%s", fmt::base57(output)); + std::memcpy(&hash_start, output, sizeof(hash_start)); } else { @@ -7413,7 +7415,7 @@ void spu_recompiler_base::dump(const spu_program& result, std::string& out) { if (m_block_info[bb.first / 4]) { - fmt::append(out, "A: [0x%05x] %s\n", bb.first, m_entry_info[bb.first / 4] ? (m_ret_info[bb.first / 4] ? "Chunk" : "Entry") : "Block"); + fmt::append(out, "A: [0x%05x] %s [%s]\n", bb.first, m_entry_info[bb.first / 4] ? (m_ret_info[bb.first / 4] ? "Chunk" : "Entry") : "Block", spu_block_hash{(hash_start & -65536) + bb.first / 4}); fmt::append(out, "\t F: 0x%05x\n", bb.second.func); diff --git a/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp b/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp index 2e14b09517..d42acd3560 100644 --- a/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp @@ -2160,6 +2160,14 @@ public: } } + if (bb.preds.size() >= 2) + { + if (g_cfg.core.spu_prof || g_cfg.core.spu_debug) + { + m_ir->CreateStore(m_ir->getInt64((m_hash_start & -65536) | (baddr >> 2)), spu_ptr(&spu_thread::block_hash)); + } + } + // State check at the beginning of the chunk if (need_check || (bi == 0 && g_cfg.core.spu_block_size != spu_block_size_type::safe)) { diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 7b70dcdbd2..b9a77d7696 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -164,7 +164,7 @@ void fmt_class_string::format(std::string& out, u64 arg) out.resize(out.size() - 4); // Print chunk address from lowest 16 bits - fmt::append(out, "...chunk-0x%05x", (arg & 0xffff) * 4); + fmt::append(out, "-0x%05x", (arg & 0xffff) * 4); } enum class spu_block_hash_short : u64{};