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

Jits: Discard registers which we know will be overwritten #9351

Merged
merged 2 commits into from Apr 6, 2021

Conversation

JosJuice
Copy link
Member

This pull request adds a new "discarded" state for registers. Discarding a register is like flushing it, but without actually writing its value back to memory. We can discard a register only when it is guaranteed that no instruction will read from the register before it is next written to.

Discarding reduces the register pressure a little, and can also let us skip a few flushes on interpreter fallbacks.

@merryhime
Copy link
Contributor

x64 changes lgtm

@JosJuice JosJuice force-pushed the discard-registers branch 2 times, most recently from 8e7ca98 to ef402e4 Compare January 3, 2021 14:32
@@ -551,6 +551,10 @@ void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const Gekk
code->outputFPRF = (opinfo->flags & FL_SET_FPRF) != 0;
code->canEndBlock = (opinfo->flags & FL_ENDBLOCK) != 0;

// TODO: Is it possible to determine that some FPU instructions never cause exceptions?
code->canCauseException =
(opinfo->flags & (FL_LOADSTORE | FL_USE_FPU | FL_PROGRAMEXCEPTION)) != 0;
Copy link
Member

Choose a reason for hiding this comment

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

The first FPU instruction will throw an exception, so all others are fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't FPU instructions throw exceptions in other situations as well (that may not have been implemented in the JITs yet), like division by zero? (See the discussion about True Crime on IRC earlier this month)

if (op.canEndBlock || op.canCauseException)
{
gprDiscardable = BitSet32{};
fprDiscardable = BitSet32{};
Copy link
Member

Choose a reason for hiding this comment

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

I wonder, is there a reason why wantsCR, wantsFPRF, ..., is only set for op.canEndBlock?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure exactly how the logic works, and I'm also not sure if it has to do with this PR.

We've run out of space :(
This commit adds a new "discarded" state for registers.
Discarding a register is like flushing it, but without
actually writing its value back to memory. We can discard
a register only when it is guaranteed that no instruction
will read from the register before it is next written to.

Discarding reduces the register pressure a little, and can
also let us skip a few flushes on interpreter fallbacks.
@JMC47 JMC47 merged commit 99d4336 into dolphin-emu:master Apr 6, 2021
10 checks passed
@JosJuice JosJuice deleted the discard-registers branch April 6, 2021 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants