Skip to content

Commit

Permalink
SPU LLVM Precompilation
Browse files Browse the repository at this point in the history
Implement function SPU function discovery in images or random SPU code�
  • Loading branch information
elad335 committed Aug 28, 2023
1 parent 290ff5b commit b5faf58
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 22 deletions.
9 changes: 8 additions & 1 deletion rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,13 @@ static void ppu_check_patch_spu_images(const ppu_module& mod, const ppu_segment&

if (prog.p_type == 0x1u /* LOAD */ && prog.p_filesz > 0u)
{
if (prog.p_vaddr)
{
extern void utilize_spu_data_segment(u32 vaddr, const void* ls_data_vaddr, u32 size);

utilize_spu_data_segment(prog.p_vaddr, (elf_header + prog.p_offset), prog.p_filesz);
}

sha1_update(&sha2, (elf_header + prog.p_offset), prog.p_filesz);
}

Expand All @@ -1119,7 +1126,7 @@ static void ppu_check_patch_spu_images(const ppu_module& mod, const ppu_segment&

if (!name.empty())
{
fmt::append(dump, "\n\tSPUNAME: '%s'", name);
fmt::append(dump, "\n\tSPUNAME: '%s' (image addr: 0x%x)", name, seg.addr + i);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4030,7 +4030,7 @@ extern void ppu_initialize()

const std::string mount_point = vfs::get("/dev_flash/");

bool dev_flash_located = !Emu.GetCat().ends_with('P') && Emu.IsPathInsideDir(Emu.GetBoot(), mount_point) && g_cfg.core.ppu_llvm_precompilation;
bool dev_flash_located = !Emu.GetCat().ends_with('P') && Emu.IsPathInsideDir(Emu.GetBoot(), mount_point) && g_cfg.core.llvm_precompilation;

if (compile_fw || dev_flash_located)
{
Expand All @@ -4050,7 +4050,7 @@ extern void ppu_initialize()
}

// Avoid compilation if main's cache exists or it is a standalone SELF with no PARAM.SFO
if (compile_main && g_cfg.core.ppu_llvm_precompilation && !Emu.GetTitleID().empty() && !Emu.IsChildProcess())
if (compile_main && g_cfg.core.llvm_precompilation && !Emu.GetTitleID().empty() && !Emu.IsChildProcess())
{
// Try to add all related directories
const std::set<std::string> dirs = Emu.GetGameDirs();
Expand Down
12 changes: 12 additions & 0 deletions rpcs3/Emu/Cell/RawSPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ void spu_load_exec(const spu_exec_object& elf)

spu->status_npc = {SPU_STATUS_RUNNING, elf.header.e_entry};
atomic_storage<u32>::release(spu->pc, elf.header.e_entry);

const auto funcs = spu->discover_functions(spu->ls, umax);

for (u32 addr : funcs)
{
spu_log.success("Found SPU function at: 0x%08x", addr);
}

if (!funcs.empty())
{
spu_log.success("Found %u SPU functions", funcs.size());
}
}

void spu_load_rel_exec(const spu_rel_object& elf)
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/SPUOpcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ union spu_opcode_t
bf_t<u32, 7, 18> i18; // 7..24
};

inline u32 spu_branch_target(u32 pc, u32 imm = 0)
constexpr u32 spu_branch_target(u32 pc, u32 imm = 0)
{
return (pc + (imm << 2)) & 0x3fffc;
}

inline u32 spu_ls_target(u32 pc, u32 imm = 0)
constexpr u32 spu_ls_target(u32 pc, u32 imm = 0)
{
return (pc + (imm << 2)) & 0x3fff0;
}

inline u32 spu_decode(u32 inst)
constexpr u32 spu_decode(u32 inst)
{
return inst >> 21;
}
Expand Down
Loading

0 comments on commit b5faf58

Please sign in to comment.