From 3d2229ca0577066fc7cd45c15a742d05551c7f42 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi Date: Mon, 28 Aug 2023 12:20:17 +0300 Subject: [PATCH] SPU LLVM Precompilation Fixup --- rpcs3/Emu/Cell/SPURecompiler.cpp | 39 ++++++++++++++------------------ rpcs3/Emu/Cell/SPUThread.cpp | 14 ------------ 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index acef8a2747..3b863dd589 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -699,7 +699,19 @@ void spu_cache::initialize() auto data_list = std::move(g_fxo->get().data); g_fxo->get().had_been_used = true; - atomic_t data_indexer{}; + const bool spu_precompilation_enabled = func_list.empty() && g_cfg.core.spu_cache && g_cfg.core.llvm_precompilation; + + if (spu_precompilation_enabled) + { + // What compiles in this case goes straight to disk + g_fxo->get() = std::move(cache); + } + else + { + data_list.clear(); + } + + atomic_t data_indexer = 0; if (g_cfg.core.spu_decoder == spu_decoder_type::dynamic || g_cfg.core.spu_decoder == spu_decoder_type::llvm) { @@ -742,12 +754,9 @@ void spu_cache::initialize() u32 add_count = ::size32(func_list); - if (func_list.empty()) + for (auto& sec : data_list) { - for (auto& sec : data_list) - { - add_count += sec.funcs.size(); - } + add_count += sec.funcs.size(); } g_progr_ptotal += add_count; @@ -847,12 +856,6 @@ void spu_cache::initialize() result++; } - if (!func_list.empty() || !g_cfg.core.llvm_precompilation) - { - // Cache has already been initiated or the user does not want to precompile SPU programs - return result; - } - u32 last_sec_idx = umax; for (usz func_i = data_indexer++;; func_i = data_indexer++, g_progr_pdone++) @@ -1077,7 +1080,7 @@ void spu_cache::initialize() } // Initialize global cache instance - if (g_cfg.core.spu_cache) + if (g_cfg.core.spu_cache && cache) { g_fxo->get() = std::move(cache); } @@ -2900,8 +2903,6 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) } } - spu_program result2 = result; - while (lsa > 0 || limit < 0x40000) { const u32 initial_size = ::size32(result.data); @@ -3348,13 +3349,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) { workload.clear(); workload.push_back(entry_point); - if (!m_bbs.count(entry_point)) - { - std::string func_bad; - dump(result2, func_bad); - spu_log.error("%s", func_bad); - return {}; - } + ensure(m_bbs.count(entry_point)); std::basic_string new_entries; diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 9376663893..e5648f9cd0 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -487,20 +487,6 @@ std::array op_branch_targets(u32 pc, spu_opcode_t op) case spu_itype::BRASL: { const int index = (type == spu_itype::BR || type == spu_itype::BRA || type == spu_itype::BRSL || type == spu_itype::BRASL ? 0 : 1); - - // if (type == spu_itype::BRASL || type == spu_itype::BRA) - // { - // res[index] = spu_branch_target(0, op.i16); - // } - // else - // { - // // Treat i16 as signed, this allows the caller to detect "overflows" and "underflows" in address in order to detect invalid branches - // // Example: - // // [0x3fffc] BR +4 -> BR 0 -> invalid - // // [0x3fffc] BR 0x3fff4 -> BR 0 -> invalid - // const u32 add = static_cast(op.si16); - // } - res[index] = (spu_branch_target(type == spu_itype::BRASL || type == spu_itype::BRA ? 0 : pc, op.i16)); if (res[0] == res[1])