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

PPCAnalyst: Less strict interrupt checks in CanSwapAdjacentOps #10172

Merged
merged 1 commit into from Jan 9, 2022

Conversation

JosJuice
Copy link
Member

When these checks were originally added, we didn't have the nice canCauseException attribute. Now we do, so let's use it.

Split out from PR #9857, because it looks like that PR isn't getting reviewed any time soon.

@Rumi-Larry
Copy link

Split out from PR #9857, because it looks like that PR isn't getting reviewed any time soon.

I am curious why that tends to happen. Why certain promising pr's just get left abandoned?

@JosJuice
Copy link
Member Author

Because properly reviewing takes effort and skill, especially if the change is to code you're not familiar with. The number of people who are active on Dolphin and understand this part of the codebase is smaller than you might think.

@Rumi-Larry
Copy link

@JosJuice I was thinking, wouldn't it be better if there was a unified non-profit organization, that would coordinate and crowdfund emulator projects of all kinds of consoles?

@JosJuice
Copy link
Member Author

Hiring someone to work on an emulator as an actual job costs a lot of money, and doesn't guarantee that you'll get someone who actually knows this stuff better than the volunteers there are right now.

Anyway, this is getting rather off topic. If you want to discuss this further you should join us on IRC.

@Sintendo
Copy link
Member

I toyed around with this for a bit last night, mainly to see what cases it allows that it didn't previously. The case that came up most frequently is moving blr downwards further by swapping it with arithmetic instructions. I don't really understand PPCAnalyst well enough to know whether that's a good idea or not.

@JosJuice
Copy link
Member Author

Reordering blr sounds dangerous. When I wrote this patch, I may have been assuming that all branch instructions have canCauseException set to true, but that's not actually the case.

I've added a check to abort if a is a branch. Could you re-test?

What confuses me is how a could end up being blr to begin with... Because of how ReorderInstructionsCore works, a should always be a CR instruction, an instruction that sets the carry flag, or a cmp instruction.

@Sintendo
Copy link
Member

It confused me too, but for whatever reason blr is explicitly marked as a CR instruction during analysis: https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/Core/PowerPC/PPCAnalyst.cpp#L649

I'll be sure to give this another go later this week.

@JosJuice
Copy link
Member Author

Good catch!

That's a strange piece of code... My best guess at its purpose is that it tries to make it so that if an instruction writes to a condition register, and then no instruction reads from that condition register before the next blr, we don't need to store the new value of the condition register to ppcState. A kind of optimization based on making assumptions about the ABI. It accomplishes this in a slightly roundabout way, setting outputCR0 = true as a way of making the "Scan for flag dependencies" loop later on set wantsCR0 = false.

Perhaps I will submit a separate PR later to get rid of this. But for now, the check I added should be sufficient for making this PR not break anything.

@JosJuice
Copy link
Member Author

Created it as PR #10284.

Copy link
Member

@Sintendo Sintendo left a comment

Choose a reason for hiding this comment

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

Gave this another go. blr is indeed no longer considered for swaps and the remaining 'new' swaps all look sane.

When these checks were originally added, we didn't have the nice
canCauseException attribute. Now we do, so let's use it.
@JosJuice JosJuice merged commit e5ef597 into dolphin-emu:master Jan 9, 2022
10 checks passed
@JosJuice JosJuice deleted the reorder-exception branch January 9, 2022 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants