Optimize DateTime constructors (DateToTicks and IsLeapYear)#46245
Closed
EgorBo wants to merge 2 commits intodotnet:masterfrom
Closed
Optimize DateTime constructors (DateToTicks and IsLeapYear)#46245EgorBo wants to merge 2 commits intodotnet:masterfrom
EgorBo wants to merge 2 commits intodotnet:masterfrom
Conversation
Collaborator
|
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. |
EgorBo
commented
Dec 19, 2020
| return (year & 3) == 0 && ((year & 15) == 0 || | ||
| // TODO: optimize "(uint)year % 25 != 0" in JIT to produce: | ||
| (year * -1030792151 > 171798691)); | ||
| } |
Member
Author
There was a problem hiding this comment.
EgorBo
commented
Dec 19, 2020
| uint y = (uint)(year - 1); | ||
| uint n = y * 365 + y / 4 - y / 100 + y / 400 + (uint)days[month - 1] + (uint)day - 1; | ||
| return n * TicksPerDay; | ||
| } |
Member
Author
There was a problem hiding this comment.
y is int but always is in the [1..9999] range so can be treated as unsigned (X /u C is faster than X / C) sharplab.io
jkotas
reviewed
Dec 19, 2020
|
|
||
| int y = year - 1; | ||
| int n = y * 365 + y / 4 - y / 100 + y / 400 + days[month - 1] + day - 1; | ||
| uint y = (uint)(year - 1); |
jkotas
reviewed
Dec 19, 2020
| } | ||
| return (year & 3) == 0 && ((year & 15) == 0 || (year % 25) != 0); | ||
| return (year & 3) == 0 && ((year & 15) == 0 || | ||
| // TODO: optimize "(uint)year % 25 != 0" in JIT to produce: |
Member
There was a problem hiding this comment.
Yes, we should fix the JIT instead of sprinkling manually generated magic div and mod everywhere. I had the same comment in #45479 (comment)
Member
Author
There was a problem hiding this comment.
ah didn't notice that pr 🙂
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Just a nano-optimization to make some of the
DateTimeconstructors a bit faster, e.g.:Codegen diff for
CreateDate_var: https://www.diffchecker.com/BOTFFqql (336 bytes -> 286 bytes), for arm64: https://www.diffchecker.com/H8xUCOtO (448 bytes -> 400 bytes)Feel free to close if you think the hacks aren't worth it 🙂