-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Convert.Try{From/To}HexString #86556
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3a0c31e
Add implementation
hrrrrustic cc13dca
Add tests
hrrrrustic eecaed0
Update conditions
hrrrrustic b8cb6dd
Add goto
hrrrrustic 772208f
Some fixes
hrrrrustic 7333ca3
Some fixes
hrrrrustic f23df24
Add comments
hrrrrustic 70c9321
Few more tests
hrrrrustic f80a8d3
Update ref file
hrrrrustic 9fd5c99
twiced -> twice
hrrrrustic d063d4f
Fix null test
hrrrrustic 986c8fa
try fix roundtrip test
hrrrrustic c644e59
fix tabs & naming
hrrrrustic 794eff8
var -> int
hrrrrustic 8a858be
Merge remote-tracking branch 'origin/main' into issue-78472
hrrrrustic 6e48f51
Update implementation
hrrrrustic 071e5f4
Fix tests
hrrrrustic 80431ab
fix slicing
hrrrrustic 38d018f
More tests
hrrrrustic 948616f
update xml comments
hrrrrustic af59a7f
Fill values on invalid data result
hrrrrustic dbfe893
Fix tests?
hrrrrustic 30afc43
Try update loop
hrrrrustic 010c836
Merge remote-tracking branch 'origin/main' into issue-78472
hrrrrustic f532064
try fix target buffer size error
hrrrrustic 9afd0cb
Remove Vectorized copy-paste
hrrrrustic e7439d4
fix naming
hrrrrustic f247ed0
Apply suggestions from code review
adamsitnik 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
Add goto
- Loading branch information
commit b8cb6dd43fe2a002f252cfd995d0c45028a5e6e2
There are no files selected for viewing
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
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.
Use concrete types here. Same on other places.
Perf-wise this could be
nuint
, so all the division and modulo operations are treated as (fast) bit-operations.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.
That's interesting. We rarely use native width types except in interop contexts. @jkotas @EgorBo is it correct that in hot code of this type, it can have perf benefit for simple storage of counters and offsets?
Uh oh!
There was an error while loading. Please reload this page.
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.
Afair, JIT knows that Span.Length (and Array.Length as well) are never negative so it doesn't need extra efforts from the C# side 🙂 e.g.:
(some of the changes landed in .NET 8.0 so might be not visible on sharplab yet)
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.
Right -- I'm not aware of patterns where nuint gives better code.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for the reminder -- I'll forget sometimes about the new JIT-goodness.
Quite a lot of vectorized code uses the native width types, because memory operations don't need (sign-) extending moves then (e.g.
Unsafe.Add(ref ptr, intVariable)
vs.Unsafe.Add(ref ptr, nuintVariable)
-- https://godbolt.org/z/v8E31Wdsx).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.
Would
Math.DivRem
be more efficient here? Especially once it becomes an intrinsic.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.
I doubt it, since the JIT optimizes
length % 2 != 0
to(length & 1) != 0
.Uh oh!
There was an error while loading. Please reload this page.
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.
That comment wasn't just about the single length check, but also the division done a few lines later. DivRem in theory combines the two operations.
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.
The JIT can optimize
(uint)length / 2
to(uint)length >> 1
. On X86,DivRem
would likely be implemented using adiv
instruction, which is an relatively expensive operation.