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

SPU/PPU LLVM: Fixups and minor optimizations #14616

Merged
merged 7 commits into from
Sep 5, 2023
Merged

Conversation

elad335
Copy link
Contributor

@elad335 elad335 commented Sep 4, 2023

  • Fix greedy PPU instruction search, there was a typo there and it was not considering BCLR and BCCTR.
  • Add an optimization for PPU LLVM whener there are direct-unconditional branches following one another or ending up in an empty function (BLR).
  • Add an optimization regarding PPU traps conditions, detect "always trap" forms and detect possible but theorectical simple "inequality" trap form. (either when both signed greater/lower or unsigned greater/lower are set).
  • Improve SPU LLVM precompilation a bit.
  • PPU LLVM: Patch unregistered BLRs.

May fix #14555
May fix #14600
May fix #14613

@elad335 elad335 added CPU Bugfix Optimization Optimizes existing code Caution: Breaks Backwards Compatibility Changes that breaks backwards compatibility labels Sep 4, 2023
@elad335
Copy link
Contributor Author

elad335 commented Sep 4, 2023

Caution: invalidates cache of some games.

@Nekotekina
Copy link
Member

I didn't get why it's supposed to invalidate caches?

@elad335
Copy link
Contributor Author

elad335 commented Sep 4, 2023

Because of the analyzer fixes.

@JimScript
Copy link

JimScript commented Sep 4, 2023

Hey, Jak and Daxter works again, even the savesates load now(and the precompiling is pretty fast too).
Edit: Well it looks like there's still a problem when going into a new area in a savestate, I get a black screen with a few:
E SYS: 'sys_fs_lseek' failed with 0x8001002a : CELL_EBADF
But I don't know if this relates to the problem at hand.
Edit2:Eh, it happens with both interpreters, so I'm guessing not.

@solarmystic
Copy link

Confirmed to fix #14600

Starting a New Game on a new profile works again.

image

else if (u32 target0 = (test_op.aa ? 0 : target) + (type == ppu_itype::B ? +test_op.bt24 : +test_op.bt14);
target0 < segs[0].addr || target0 >= segs[0].addr + segs[0].size)
else if (u32 target0 = (test_op.aa ? 0 : target) + (type0 == ppu_itype::B ? +test_op.bt24 : +test_op.bt14);
(type0 == ppu_itype::B || ppu_itype::BC) && target0 < segs[0].addr || target0 >= segs[0].addr + segs[0].size)
Copy link
Contributor

Choose a reason for hiding this comment

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

Clang produces warnings:

[94/535] Building CXX object rpcs3/Emu/CMakeFiles/rpcs3_emu.dir/Cell/PPUAnalyser.cpp.obj
C:/src/rpcs3/rpcs3/Emu/Cell/PPUAnalyser.cpp:1891:31: warning: converting the enum constant to a boolean [-Wint-in-bool-context]
                                                        (type0 == ppu_itype::B || ppu_itype::BC) && target0 < segs[0].addr || target0 >= segs[0].addr + segs[0].size)
                                                                               ^
C:/src/rpcs3/rpcs3/Emu/Cell/PPUAnalyser.cpp:1891:49: warning: '&&' within '||' [-Wlogical-op-parentheses]
                                                        (type0 == ppu_itype::B || ppu_itype::BC) && target0 < segs[0].addr || target0 >= segs[0].addr + segs[0].size)
                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ ~~
C:/src/rpcs3/rpcs3/Emu/Cell/PPUAnalyser.cpp:1891:49: note: place parentheses around the '&&' expression to silence this warning
                                                        (type0 == ppu_itype::B || ppu_itype::BC) && target0 < segs[0].addr || target0 >= segs[0].addr + segs[0].size)
                                                                                                 ^
                                                        (
                    )
2 warnings generated.

@@ -4694,6 +4702,11 @@ bool ppu_initialize(const ppu_module& info, bool check_only)

const u64 addr = reinterpret_cast<uptr>(ensure(jit_mod.funcs[index++]));

if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
Copy link
Contributor

Choose a reason for hiding this comment

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

Clang produces warnings:

[137/535] Building CXX object rpcs3/Emu/CMakeFiles/rpcs3_emu.dir/Cell/PPUThread.cpp.obj
C:/src/rpcs3/rpcs3/Emu/Cell/PPUThread.cpp:4724:23: warning: & has lower precedence than ==; == will be evaluated first [-Wparentheses]
                        if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
                            ~~~~~~~~~~~~~~~^
C:/src/rpcs3/rpcs3/Emu/Cell/PPUThread.cpp:4724:23: note: place parentheses around the '==' expression to silence this warning
                        if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
                                           ^
                            (             )
C:/src/rpcs3/rpcs3/Emu/Cell/PPUThread.cpp:4724:23: note: place parentheses around the & expression to evaluate it first
                        if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
                                           ^
                                         (            )
C:/src/rpcs3/rpcs3/Emu/Cell/PPUThread.cpp:4748:23: warning: & has lower precedence than ==; == will be evaluated first [-Wparentheses]
                        if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
                            ~~~~~~~~~~~~~~~^
C:/src/rpcs3/rpcs3/Emu/Cell/PPUThread.cpp:4748:23: note: place parentheses around the '==' expression to silence this warning
                        if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
                                           ^
                            (             )
C:/src/rpcs3/rpcs3/Emu/Cell/PPUThread.cpp:4748:23: note: place parentheses around the & expression to evaluate it first
                        if (func.size == 4 & !BLR_func && *info.get_ptr<u32>(func.addr) == ppu_instructions::BLR())
                                           ^
                                         (            )
2 warnings generated.

@nastys
Copy link
Contributor

nastys commented Sep 15, 2023

This seems to break the "Unlock all songs and modules" patch in Hatsune Miku: Project DIVA Dreamy Theater extend (and possibly others) when using PPU LLVM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Caution: Breaks Backwards Compatibility Changes that breaks backwards compatibility CPU LLVM Related to LLVM instruction decoders Optimization Optimizes existing code
Projects
None yet
6 participants