Extend uses count from ushort to uint on Operand Data structure #3374
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.
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 aushort
. 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
touint
, 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 aushort
type, so I had to adduint
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.