-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Optimize division by constant after AND or RSZ #55778
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Moved inlining changes to separate PR #56466 |
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.
Changes looks good. Thank you!
Did you run superpmi and can you share the diff numbers across benchmarks/libraries/asp?
@@ -28,7 +28,7 @@ namespace System | |||
// Maps to December 31 year 9999. The value calculated from "new DateTime(9999, 12, 31).Ticks / TimeSpan.TicksPerDay" | |||
private const int MaxDayNumber = 3_652_058; | |||
|
|||
private static int DayNumberFromDateTime(DateTime dt) => (int)(dt.Ticks / TimeSpan.TicksPerDay); | |||
private static int DayNumberFromDateTime(DateTime dt) => (int)((ulong)dt.Ticks / TimeSpan.TicksPerDay); |
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.
How does this cast help?
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.
It changes the division from signed to unsigned.
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.
Another possible source of reducing bits would be small types (don't think it is worth doing it now though, you could leave a TODO
for someone to take a second look if/after #55186 is merged).
PMI diffs for System.Private.CoreLib:
Detailed diffs for win-x64
|
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.
LGTM
If the dividend operand is
AND
orRSZ
with a constant then the number of input bits can be reduced which helps generate more optimal magic numbers.Also adopted a couple more functions to use unsigned division.
Diff example: