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

Extend uses count from ushort to uint on Operand Data structure #3374

Merged
merged 1 commit into from Jun 5, 2022

Conversation

gdkchan
Copy link
Member

@gdkchan gdkchan commented May 31, 2022

Currently, the operand uses count (and capacity) is limited to a ushort, mostly to save memory. The maximum number of uses a variable may have is then 65535, since this is the maximum value you can store on a ushort. For 99% of the games that is enough, however there are a few games with very large blocks using mostly the same register over and over again. This pattern can easily reach the limit.

The fix here is simply changing the type used to store the uses count and capacity from ushort to uint, which now increases the limit to 2147483647 which is the signed 32-bit integer maximum value. The actual amount of memory used didn't actually increase since that, due to alignment, the structure size in memory was 48 bytes. It had 5 unused bytes, so now 4 of them are being occupied by the larger counts, and theres now 1 unused byte. I had to duplicate some code as the existing functions expect a ushort type, so I had to add uint overloads. With the new generic math feature that will be added on .NET 7, we can eventually de-duplicate this again.

This fixes the overflow exception when booting Taiko Risshiden V DX. I'm pretty sure that there was another game with a similar issue, but now I can't find it.
image
image

@gdkchan gdkchan added cpu Related to ARMeilleure fix Fix something labels May 31, 2022
Copy link
Member

@riperiperi riperiperi left a comment

Choose a reason for hiding this comment

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

LGTM

@gdkchan gdkchan merged commit 633c5ec into Ryujinx:master Jun 5, 2022
@gdkchan gdkchan deleted the uint-uses-count branch June 5, 2022 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpu Related to ARMeilleure fix Fix something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants