Skip to content

Commit

Permalink
PPU LLVM: upgrade to GHC call conv
Browse files Browse the repository at this point in the history
Get rid of some global variables.
Implement ppu_escape (unused yet).
Bump PPU cache version to v4.
  • Loading branch information
Nekotekina committed Feb 1, 2021
1 parent aeeceb7 commit 0c034ad
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 109 deletions.
33 changes: 31 additions & 2 deletions rpcs3/Emu/Cell/PPUFunction.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "PPUFunction.h"
#include "Utilities/JIT.h"

#include "PPUModule.h"

Expand Down Expand Up @@ -1888,7 +1889,7 @@ extern std::string ppu_get_variable_name(const std::string& _module, u32 vnid)
return fmt::format("0x%08X", vnid);
}

std::vector<ppu_function_t>& ppu_function_manager::access()
std::vector<ppu_function_t>& ppu_function_manager::access(bool ghc)
{
static std::vector<ppu_function_t> list
{
Expand All @@ -1907,15 +1908,43 @@ std::vector<ppu_function_t>& ppu_function_manager::access()
},
};

return list;
static std::vector<ppu_function_t> list_ghc
{
build_function_asm<ppu_function_t>([](asmjit::X86Assembler& c, auto& args)
{
using namespace asmjit;

c.mov(args[0], x86::rbp);
c.jmp(imm_ptr(list[0]));
}),
build_function_asm<ppu_function_t>([](asmjit::X86Assembler& c, auto& args)
{
using namespace asmjit;

c.mov(args[0], x86::rbp);
c.jmp(imm_ptr(list[1]));
}),
};

return ghc ? list_ghc : list;
}

u32 ppu_function_manager::add_function(ppu_function_t function)
{
auto& list = access();
auto& list2 = access(true);

list.push_back(function);

// Generate trampoline
list2.push_back(build_function_asm<ppu_function_t>([&](asmjit::X86Assembler& c, auto& args)
{
using namespace asmjit;

c.mov(args[0], x86::rbp);
c.jmp(imm_ptr(function));
}));

return ::size32(list) - 1;
}

Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/PPUFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class ppu_function_manager
};

// Access global function list
static std::vector<ppu_function_t>& access();
static std::vector<ppu_function_t>& access(bool ghc = false);

static u32 add_function(ppu_function_t function);

Expand All @@ -276,9 +276,9 @@ class ppu_function_manager
}

// Read all registered functions
static inline const auto& get()
static inline const auto& get(bool llvm = false)
{
return access();
return access(llvm);
}

static inline u32 func_addr(u32 index)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link)
};

// Initialize double-purpose fake OPD array for HLE functions
const auto& hle_funcs = ppu_function_manager::get();
const auto& hle_funcs = ppu_function_manager::get(g_cfg.core.ppu_decoder == ppu_decoder_type::llvm);

// Allocate memory for the array (must be called after fixed allocations)
ppu_function_manager::addr = vm::alloc(::size32(hle_funcs) * 8, vm::main);
Expand Down

0 comments on commit 0c034ad

Please sign in to comment.