-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Replace ExtractMostSignificantBits+BitOp patterns with Vector helper methods #126841
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
Draft
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/replace-extract-msb-with-vector-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff0f007
Replace ExtractMostSignificantBits+BitOp patterns with Vector helpers
Copilot 31f94e3
Remove IndexOfFirstMatch wrappers; inline IndexOfWhereAllBitsSet dire…
Copilot 499c77e
Revert Vector128.cs, Vector64.cs, and HammingDistance.cs changes
Copilot 8dc533d
Use CountMatches internal helper in SpanHelpers.T.cs to avoid x64 reg…
Copilot d3a08e4
Clean up extra blank lines from removed IndexOfFirstMatch methods
Copilot 9b3f39f
Replace EMSB+BitOp patterns with IndexOfFirstMatch/IndexOfLastMatch i…
Copilot 8a7e5a3
Merge branch 'main' into copilot/replace-extract-msb-with-vector-func…
EgorBo 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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
@EgorBo, so on x64 this is basically going to do:
and on Arm64 (neoverse v2):
More ideally the JIT could recognize this general pattern and generate this instead for x64:
and this on Arm64:
This would make it significantly cheaper for both, but I think requires us to recognize the
!= Zerofollowed by anCount/IndexOf/LastIndexOfpattern. Specifically I think CSE would trivially handle this for Arm64, but on x64 we'd need to transform the!= Zeroin that case so CSE could kick in.What are your thoughts on this?
The alternative is we setup the managed code to look like this:
Then we'd get this (roughly) on x64:
and this on Arm64:
This is a little less than half the cost on match on both platforms, but has slightly higher cost for the no match scenario.
But I expect this is also difficult to pattern match and handle to get it to generate what we want in the first scenario, right?
We should probably pick one and have that be the "recommended pattern" where we then have the JIT handle it for the ideal codegen. -- The "other" other thing we could do is use
Vector128.AnyWhereAllBitsSet(mask)instead ofmask != Vector128<T>.Zero, which might then be easier to optimize overall, but interested in your thoughts so we can work towards getting it optimized and have managed follow our desired shape.