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

JitArm64: Fix special cases of cmp #11564

Merged
merged 1 commit into from Feb 14, 2023

Conversation

JosJuice
Copy link
Member

This fixes a regression from 592ba31. When a was a constant 0 and b was a non-constant 0x80000000, the 32-bit negation operation would overflow, causing an incorrect result. The sign extension needs to happen before the negation to avoid overflow.

Note that I can't merge the SXTW and NEG into one instruction. NEG is an alias for SUB with the first operand being set to ZR, but "SUB (extended register)" treats register 31 as SP instead of ZR.

I've also changed the order for the case where a is a constant 0xFFFFFFFF. I don't think the order actually affects correctness here, but let's use the same order for all the cases since it makes the code easier to reason about.

This fixes a regression from 592ba31. When `a` was a constant 0 and `b`
was a non-constant 0x80000000, the 32-bit negation operation would
overflow, causing an incorrect result. The sign extension needs to happen
before the negation to avoid overflow.

Note that I can't merge the SXTW and NEG into one instruction.
NEG is an alias for SUB with the first operand being set to ZR,
but "SUB (extended register)" treats register 31 as SP instead of ZR.

I've also changed the order for the case where `a` is a constant
0xFFFFFFFF. I don't think the order actually affects correctness here,
but let's use the same order for all the cases since it makes the code
easier to reason about.
@JosJuice
Copy link
Member Author

This fixes Mario & Sonic at the Olympic Winter Games.

@Sintendo
Copy link
Member

Oops, nice catch! 👌

@AdmiralCurtiss AdmiralCurtiss merged commit 661b74f into dolphin-emu:master Feb 14, 2023
@JosJuice JosJuice deleted the jitarm64-cmp-order branch February 14, 2023 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants