From 8c0084261421d06d8ff820b6064e5231b6e9137b Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:14:30 +0200 Subject: [PATCH 1/2] Fixup std::vector to std::span --- rpcs3/Emu/Cell/SPUCommonRecompiler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp index 45b0bfe0df..2baaa15705 100644 --- a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp @@ -558,7 +558,7 @@ extern void utilize_spu_data_segment(u32 vaddr, const void* ls_data_vaddr, u32 s return; } - std::vector data(size / 4, 0); + std::vector data(size / 4); std::memcpy(data.data(), ls_data_vaddr, size); spu_cache::precompile_data_t obj{vaddr, std::move(data)}; @@ -951,7 +951,7 @@ void spu_cache::initialize(bool build_existing_cache) u32 next_func = 0; u32 sec_addr = umax; u32 sec_idx = 0; - std::vector inst_data; + std::span inst_data; // Try to get the data this index points to for (auto& sec : data_list) @@ -961,7 +961,7 @@ void spu_cache::initialize(bool build_existing_cache) const usz func_idx = func_i - passed_count; sec_addr = sec.vaddr; func_addr = ::at32(sec.funcs, func_idx); - inst_data = sec.inst_data; + inst_data = { sec.inst_data.data(), sec.inst_data.size() }; next_func = sec.funcs.size() >= func_idx ? ::narrow(sec_addr + inst_data.size() * 4) : sec.funcs[func_idx]; break; } From c5bbee7a0a8dc3fc1d31bf7fe1de8c86afbf9fb5 Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:47:01 +0200 Subject: [PATCH 2/2] SPU: Fixup code comparison --- rpcs3/Emu/Cell/SPUCommonRecompiler.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp index 2baaa15705..105b794862 100644 --- a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp @@ -37,21 +37,31 @@ constexpr u32 s_reg_max = spu_recompiler_base::s_reg_max; template struct span_less { - static int compare(const std::span& this_, const std::span& that) noexcept + static int compare(const std::span& lhs, const std::span& rhs) noexcept { - int res = std::memcmp(this_.data(), that.data(), std::min(this_.size_bytes(), that.size_bytes())); - - if (res == 0 && this_.size() != that.size()) + // TODO: Replace with std::lexicographical_compare_three_way when it becomes available to all compilers + for (usz i = 0, last = std::min(lhs.size(), rhs.size()); i != last; i++) { - res = this_.size() < that.size() ? -1 : 1; + const T vl = lhs[i]; + const T vr = rhs[i]; + + if (vl != vr) + { + return vl < vr ? -1 : 1; + } } - return res; + if (lhs.size() != rhs.size()) + { + return lhs.size() < rhs.size() ? -1 : 1; + } + + return 0; } - bool operator()(const std::span& this_, const std::span& that) const noexcept + bool operator()(const std::span& lhs, const std::span& rhs) const noexcept { - return compare(this_, that) < 0; + return compare(lhs, rhs) < 0; } };