Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental] PPU LLVM: Recycle identical functions #15308

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

elad335
Copy link
Contributor

@elad335 elad335 commented Mar 11, 2024

I noticed that more then 40% of functions examined in some executables, occur more than once throughout the executable. So, why not reuse their code when possible in order to reduce compilation and link time?
There are some exceptions, not all identical functions are truly identical in meaning if they are located elsewhere so I also check if they contain any relative branch that tragets external code. (which changes the meaning of the function)

Edit: because of the spectacular bugs I created when debugging this PR, I discovered a bug in sys_prx_stop_module that is fixed here. (turns it it can abort an ongoing starting process of PRX)

@elad335 elad335 added Optimization Optimizes existing code LLVM Related to LLVM instruction decoders ☘️ Power Saving Aims to reduce power consumption of RPCS3 labels Mar 11, 2024
@elad335
Copy link
Contributor Author

elad335 commented Mar 11, 2024

Who wants to test MGS4 compilation time and link time (Applying PPU code)?

@@ -3845,6 +3850,154 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<ppu_
}
}
}

if (file_queue.size() > old_size && file_queue.size() - 1 > old_size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (file_queue.size() > old_size && file_queue.size() - 1 > old_size)
if (file_queue.size() > old_size + 1)

Comment on lines 3876 to 3889
for (auto& [name, key] : s_ch_to_lang)
{
if (key == g_cfg.sys.language)
{
chosen_lang = name;
break;
}
}

if (g_cfg.sys.language == CELL_SYSUTIL_LANG_ENGLISH_GB)
{
// Fallback
chosen_lang = "us"sv;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto& [name, key] : s_ch_to_lang)
{
if (key == g_cfg.sys.language)
{
chosen_lang = name;
break;
}
}
if (g_cfg.sys.language == CELL_SYSUTIL_LANG_ENGLISH_GB)
{
// Fallback
chosen_lang = "us"sv;
}
const s32 language = g_cfg.sys.language == CELL_SYSUTIL_LANG_ENGLISH_GB ? CELL_SYSUTIL_LANG_ENGLISH_US : g_cfg.sys.language;
for (auto& [name, key] : s_ch_to_lang)
{
if (key == language)
{
chosen_lang = name;
break;
}
}


if (chosen_lang.empty())
{
// Disable optimization if other langues are selected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Disable optimization if other langues are selected
// Disable optimization if other languages are selected

rpcs3/Emu/Cell/PPUThread.cpp Outdated Show resolved Hide resolved
{
prev_fname = std::move(fname);
}
else if (!prev_fname.empty() && prev_fname.size() == fname.size())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if (!prev_fname.empty() && prev_fname.size() == fname.size())
else if (prev_fname.size() == fname.size())

const std::string_view plang = std::string_view(prev_fname).substr(j, 2);
const std::string_view flang = std::string_view(fname).substr(j, 2);

if (plang != flang && s_ch_to_lang.count(plang) && s_ch_to_lang.count(flang))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (plang != flang && s_ch_to_lang.count(plang) && s_ch_to_lang.count(flang))
if (plang != flang && s_ch_to_lang.contains(plang) && s_ch_to_lang.contains(flang))


const std::string_view flang = std::string_view(fname).substr(j, 2);

if (s_ch_to_lang.count(flang) && chosen_lang != flang)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (s_ch_to_lang.count(flang) && chosen_lang != flang)
if (s_ch_to_lang.contains(flang) && chosen_lang != flang)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -3854,6 +4007,15 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<ppu_
for (const file_info& info : file_queue)
{
total_files_size += info.file_size;

if (!info.rec_name.empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda weird to take the negated path first.

rpcs3/Emu/Cell/PPUThread.cpp Outdated Show resolved Hide resolved
Comment on lines 3910 to 3918
usz j = 0;

for (; j < fname.size() - 7; j++)
{
if (prev_fname[j] != fname[j])
{
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the same as
const usz j = prev_fname[j].find_first_not_of(fname[j]);
?

Comment on lines 3968 to 3970
if (fname.ends_with(".self"))
{
if (prev_fname.size() == fname.size())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably be faster the other way around

@elad335 elad335 force-pushed the postpone branch 6 times, most recently from a8edced to 4a8a58c Compare March 11, 2024 17:39
@EmulationChannel
Copy link

@elad335 My Compile FW FULL SPEED 14600KF Thanks Brow !!!!!

@EmulationChannel
Copy link

Captura de tela 2024-03-11 190007
RPCS3.log

@AniLeo
Copy link
Member

AniLeo commented Mar 11, 2024

Failed to boot Guitar Hero 5

image

Log:
RPCS3.log

@user21944
Copy link

Fails to boot LittleBigPlanet 2

image

Log: RPCS3.log

@elad335 elad335 force-pushed the postpone branch 2 times, most recently from 15295c2 to b1c7f88 Compare March 12, 2024 09:58
@b1acksnow
Copy link

b1acksnow commented Mar 12, 2024

Failed to boot gt6
·F 0:00:07.613961 {PPU[0x1000000] Thread (main_thread) [liblv2: 0x00284e60]} VM: Access violation reading location 0x2f646576 (unmapped memory)
RPCS3.log

@user21944
Copy link

LittleBigPlanet 2 crashes on boot

image

Log: RPCS3.log

@EmulationChannel
Copy link

Test all games Bug Boot
Captura de tela 2024-03-12 164556
RPCS3.log

@elad335 elad335 marked this pull request as draft March 13, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LLVM Related to LLVM instruction decoders Optimization Optimizes existing code ☘️ Power Saving Aims to reduce power consumption of RPCS3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants