Skip to content
Permalink
Browse files

Fixed optimisation problem on branch in branch delay slot. Fixes Drop…

…ship - United Peace Force. Props to MrCK1 for finding the issue.
  • Loading branch information...
refractionpcsx2 committed May 19, 2018
1 parent 290397d commit 9b8244954215072068f4f83079d1c714a4b0e09a
Showing with 10 additions and 3 deletions.
  1. +10 −3 pcsx2/x86/microVU_Lower.inl
@@ -1243,18 +1243,25 @@ mVUop(mVU_XGKICK) {
//------------------------------------------------------------------

void setBranchA(mP, int x, int _x_) {
bool isBranchDelaySlot = false;

incPC(-2);
if (mVUlow.branch)
isBranchDelaySlot = true;
incPC(2);

pass1 {
if (_Imm11_ == 1 && !_x_) {
if (_Imm11_ == 1 && !_x_ && !isBranchDelaySlot) {
DevCon.WriteLn(Color_Green, "microVU%d: Branch Optimization", mVU.index);
mVUlow.isNOP = true;
return;
}
mVUbranch = x;
mVUlow.branch = x;
}
pass2 { if (_Imm11_ == 1 && !_x_) { return; } mVUbranch = x; }
pass2 { if (_Imm11_ == 1 && !_x_ && !isBranchDelaySlot) { return; } mVUbranch = x; }
pass3 { mVUbranch = x; }
pass4 { if (_Imm11_ == 1 && !_x_) { return; } mVUbranch = x; }
pass4 { if (_Imm11_ == 1 && !_x_ && !isBranchDelaySlot) { return; } mVUbranch = x; }
}

void condEvilBranch(mV, int JMPcc) {

4 comments on commit 9b82449

@prafullpcsx2

This comment has been minimized.

Copy link
Contributor

replied May 19, 2018

Good job guys. Another unplayable game fixed. :)

@ssakash

This comment has been minimized.

Copy link
Member

replied May 19, 2018

@refractionpcsx2 Was this a case where a legit branch path got optimized into a NOP? lol.

@PSI-Rockin

This comment has been minimized.

Copy link
Contributor

replied May 19, 2018

Pretty much. The optimization checks if a branch instruction has a target to the instruction after the delay slot (I have no clue why a gamedev would do this, but whatever). However, the game has that kind of branch in another branch's delay slot... and somehow, this optimization caused it to not boot.

@refractionpcsx2

This comment has been minimized.

Copy link
Member Author

replied May 19, 2018

Yeah the problem was with the horrible branch in delay slot problem, if both branches are taken, it jumps to the first branch target, runs one instruction then jumps to the second branch location. What was happening is it was nopping out the delay slot branch so it jumped to the first branch location and stayed there running completely the wrong code.

So in pseudo code It should be doing this

0x100: Branch to 0x200
0x108 Branch to 0x110
Jump
0x200 ADD blah blah
Jump
0x110 Other instruction blah blah
0x118 And another blah blah

But what was happening is it was doing

0x100: Branch to 0x200
0x108 NOP ("optimised" out branch)
Jump
0x200 ADD blah blah
0x208 SUB blah blah
0x210 MUL blah blah

etc.

Please sign in to comment.
You can’t perform that action at this time.