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.
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
Improve vectorization of String.Split #64899
Improve vectorization of String.Split #64899
Changes from 2 commits
826e568
e64d510
60d94e1
4c8c2b5
0cf5ff2
915ff82
dcadf05
8e7996c
51b102b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
does it affect codegen?
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.
Yes, it got rid of redundant range checks for
separators
, doing(uint)separators.Length <= (uint)3
is one movsxd less, but I personally thought this was cleaner. However, I can see it being too obscure with it's intent.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.
int
->nint
, it will help to avoid redundant sign extensionsThere 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 same variable is used as index to the scalar/non vectorized version at the bottom. I'll see if I can find a middle-way
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.
you can always cast it to signed just once before the scalar version
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.
Consider processing trailing elements via overlapping instead of scalar fallback
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.
There's a risk though that the code will start getting a bit complicated, I wanted to keep the code easy to follow since it's only used for a specific scenario. If you still think it's worth it, I can definitely look into it
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.
handling trailing elements in the same loop (or via a spilled iteration) shows nice improvements for small-medium sized inputs, in theory it only adds an additional check inside the loop, feel free to keep it as is, we can then follow up
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 + vector256ShortCount) <= Length
might overflow, it should bei <= Length - vector256ShortCount
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.
Besides that the
i <= len - count
version can keep thelen - count
in a register, whilsti + count
needs a repeated addition.Also local
vector256ShortCount
isn't needed, as JIT will treatVector256<ushort>.Count
as constant.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.
consider splitting this to temps for better pipelining so all compare instructions will be next to each other and so are ORs
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 might be a good idea to also use TestZ for faster out, e.g.
it's faster than movmsk
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 cast to uint here, e.g. https://sharplab.io/#v2:EYLgtghglgdgNAFxBAzmAPgAQEwEYCwAUJgAwAEmuAdAHICuYApgE5QDGKA3EUZgMwVsZAMJEA3kTJSKA2AjIBZXAAo6csgA8AlJOkTC0wxQDsZAEJQEAeQAOLCAigB7GCioAVZtAA2sAOYAWixOwk50MAjK2mQA9GTY3AbSAL66UmkyZOoK2Krq2hn6RtKYpspyWsp5EVoW1nZeji5unj7+QcwhYRFRWrHxWomGqYTJQA==
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.
When
i
is of typenint
just check if the comparison doesn't introduce any sign extensions -- please double check to be on the safe side.