Skip to content

Commit

Permalink
spu_runtime::add minor optimization
Browse files Browse the repository at this point in the history
Use preallocated vectors in trampoline generation subroutine
  • Loading branch information
Nekotekina committed Jan 28, 2019
1 parent cd58087 commit 88639ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
8 changes: 8 additions & 0 deletions Utilities/JIT.h
Expand Up @@ -7,6 +7,14 @@
#include <array>
#include <functional>

enum class jit_class
{
ppu_code,
ppu_data,
spu_code,
spu_data,
};

// ASMJIT runtime for emitting code in a single 2G region
struct jit_runtime final : asmjit::HostRuntime
{
Expand Down
20 changes: 7 additions & 13 deletions rpcs3/Emu/Cell/SPURecompiler.cpp
Expand Up @@ -257,6 +257,8 @@ spu_runtime::spu_runtime()
fs::file(m_cache_path + "spu.log", fs::rewrite);
}

workload.reserve(250);

LOG_SUCCESS(SPU, "SPU Recompiler Runtime initialized...");
}

Expand All @@ -274,7 +276,7 @@ void spu_runtime::add(std::pair<const std::vector<u32>, spu_function_t>& where,
where.second = compiled;

// Generate a dispatcher (übertrampoline)
std::vector<u32> addrv{func[0]};
addrv[0] = func[0];
const auto beg = m_map.lower_bound(addrv);
addrv[0] += 4;
const auto _end = m_map.lower_bound(addrv);
Expand All @@ -287,20 +289,11 @@ void spu_runtime::add(std::pair<const std::vector<u32>, spu_function_t>& where,
else
{
// Allocate some writable executable memory
u8* const wxptr = jit_runtime::alloc(size0 * 20, 16);
u8* const wxptr = verify(HERE, jit_runtime::alloc(size0 * 20, 16));

// Raw assembly pointer
u8* raw = wxptr;

struct work
{
u32 size;
u32 level;
u8* rel32;
std::map<std::vector<u32>, spu_function_t>::iterator beg;
std::map<std::vector<u32>, spu_function_t>::iterator end;
};

// Write jump instruction with rel32 immediate
auto make_jump = [&](u8 op, auto target)
{
Expand Down Expand Up @@ -343,7 +336,7 @@ void spu_runtime::add(std::pair<const std::vector<u32>, spu_function_t>& where,
raw += 4;
};

std::vector<work> workload;
workload.clear();
workload.reserve(size0);
workload.emplace_back();
workload.back().size = size0;
Expand All @@ -355,7 +348,7 @@ void spu_runtime::add(std::pair<const std::vector<u32>, spu_function_t>& where,
for (std::size_t i = 0; i < workload.size(); i++)
{
// Get copy of the workload info
work w = workload[i];
spu_runtime::work w = workload[i];

// Split range in two parts
auto it = w.beg;
Expand Down Expand Up @@ -523,6 +516,7 @@ void spu_runtime::add(std::pair<const std::vector<u32>, spu_function_t>& where,
}
}

workload.clear();
g_dispatcher[func[0] / 4] = reinterpret_cast<spu_function_t>(reinterpret_cast<u64>(wxptr));
}

Expand Down
15 changes: 15 additions & 0 deletions rpcs3/Emu/Cell/SPURecompiler.h
Expand Up @@ -47,7 +47,22 @@ class spu_runtime
// Debug module output location
std::string m_cache_path;

// Trampoline generation workload helper
struct work
{
u32 size;
u32 level;
u8* rel32;
std::map<std::vector<u32>, spu_function_t>::iterator beg;
std::map<std::vector<u32>, spu_function_t>::iterator end;
};
private:
// Scratch vector
std::vector<work> workload;

// Scratch vector
std::vector<u32> addrv{u32{0}};

// Trampoline to spu_recompiler_base::dispatch
spu_function_t tr_dispatch = nullptr;

Expand Down

0 comments on commit 88639ae

Please sign in to comment.