-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 crandc/creqv/crorc setting eq bit #13266
Open
JosJuice
wants to merge
2
commits into
dolphin-emu:master
Choose a base branch
from
JosJuice:jitarm64-cr-bits-1-to-31
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,8 @@ void JitArm64::GetCRFieldBit(int field, int bit, ARM64Reg out) | |
} | ||
} | ||
|
||
void JitArm64::SetCRFieldBit(int field, int bit, ARM64Reg in, bool negate) | ||
void JitArm64::SetCRFieldBit(int field, int bit, ARM64Reg in, bool negate, | ||
bool bits_1_to_31_are_set) | ||
{ | ||
gpr.BindCRToRegister(field, true); | ||
ARM64Reg CR = gpr.CR(field); | ||
|
@@ -70,7 +71,9 @@ void JitArm64::SetCRFieldBit(int field, int bit, ARM64Reg in, bool negate) | |
AND(CR, CR, LogicalImm(0xFFFF'FFFF'0000'0000, GPRSize::B64)); | ||
ORR(CR, CR, in); | ||
if (!negate) | ||
EOR(CR, CR, LogicalImm(1ULL << 0, GPRSize::B64)); | ||
EOR(CR, CR, LogicalImm(bits_1_to_31_are_set ? 0xFFFF'FFFFULL : 1ULL, GPRSize::B64)); | ||
else if (bits_1_to_31_are_set) | ||
AND(CR, CR, LogicalImm(0xFFFF'FFFF'0000'0001ULL, GPRSize::B64)); | ||
break; | ||
|
||
case PowerPC::CR_GT_BIT: // set bit 63 to !input | ||
|
@@ -632,8 +635,12 @@ void JitArm64::crXXX(UGeckoInstruction inst) | |
} | ||
} | ||
|
||
// crnor or crnand | ||
const bool negate_result = inst.SUBOP10 == 33 || inst.SUBOP10 == 225; | ||
const u32 crbd_bit = 3 - (inst.CRBD & 3); | ||
// crnor, crnand and sometimes creqv | ||
const bool negate_result = | ||
inst.SUBOP10 == 33 || inst.SUBOP10 == 225 || | ||
(inst.SUBOP10 == 289 && (crbd_bit == PowerPC::CR_EQ_BIT || crbd_bit == PowerPC::CR_GT_BIT)); | ||
bool bits_1_to_31_are_set = false; | ||
|
||
auto WA = gpr.GetScopedReg(); | ||
ARM64Reg XA = EncodeRegTo64(WA); | ||
|
@@ -653,15 +660,26 @@ void JitArm64::crXXX(UGeckoInstruction inst) | |
break; | ||
|
||
case 129: // crandc: A && ~B | ||
BIC(XA, XA, XB); | ||
BIC(WA, WA, WB); | ||
bits_1_to_31_are_set = true; | ||
break; | ||
Comment on lines
662
to
665
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A is either 0 or 1, right? If so |
||
|
||
case 193: // crxor: A ^ B | ||
EOR(XA, XA, XB); | ||
break; | ||
|
||
case 289: // creqv: ~(A ^ B) = A ^ ~B | ||
EON(XA, XA, XB); | ||
// Both of these two implementations are equally correct, but which one is more efficient | ||
// depends on which bit we're going to set in CRBD | ||
if (negate_result) | ||
{ | ||
ORR(XA, XA, XB); | ||
} | ||
else | ||
{ | ||
EON(WA, WA, WB); | ||
bits_1_to_31_are_set = true; | ||
} | ||
break; | ||
|
||
case 33: // crnor: ~(A || B) | ||
|
@@ -670,13 +688,14 @@ void JitArm64::crXXX(UGeckoInstruction inst) | |
break; | ||
|
||
case 417: // crorc: A || ~B | ||
ORN(XA, XA, XB); | ||
ORN(WA, WA, WB); | ||
bits_1_to_31_are_set = true; | ||
break; | ||
} | ||
} | ||
|
||
// Store result bit in CRBD | ||
SetCRFieldBit(inst.CRBD >> 2, 3 - (inst.CRBD & 3), XA, negate_result); | ||
SetCRFieldBit(inst.CRBD >> 2, 3 - (inst.CRBD & 3), XA, negate_result, bits_1_to_31_are_set); | ||
} | ||
|
||
void JitArm64::mfcr(UGeckoInstruction inst) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppose we replaced this whole CR_EQ_BIT case with a BFI of the lower 32 bits (which would handle the combination where negate is true and bits_1_to_31_are_set is false), then EOR with 0x1, 0xFFFF'FFFE, or 0xFFFF'FFFF for the other three combinations respectively. That would make each combination 1 or 2 instructions; are there any downsides I'm missing?