Vectorize find_first_of for 4 and 8 byte elements#4587
Merged
StephanTLavavej merged 23 commits intomicrosoft:mainfrom Apr 19, 2024
Merged
Vectorize find_first_of for 4 and 8 byte elements#4587StephanTLavavej merged 23 commits intomicrosoft:mainfrom
find_first_of for 4 and 8 byte elements#4587StephanTLavavej merged 23 commits intomicrosoft:mainfrom
Conversation
Contributor
Author
On the other hand, despite having more code, it would be an uniform approach. |
`__fallback` => `_Fallback` `__shuffle_step` => `_Shuffle_step` `__shuffle_impl` => `_Shuffle_impl` `__pcmpestri_impl` => `_Impl_pcmpestri` `__4_8_impl` => `_Impl_4_8`
StephanTLavavej
approved these changes
Apr 15, 2024
This reverts commit 1cae60f.
StephanTLavavej
approved these changes
Apr 15, 2024
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
|
Thanks for finding so many ways to improve performance! 🕵️ 💡 🚀 |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The specialized approach shuffles the needle so that every element is on every place and compares it with the haystack part. Then
ors all comparison results to find the lowest index match, then if there's a match returns it.The generic approach finds a haystack element in the needle, it is like
findwith reversed haystack/needle, but instead ofvpmovmskband checking that index and computing offset, we havevptest, as we don't need the index.Looks like we will have way better results if specialized approach is generalized,, instead of having different and simpler generic approach. But the complexity would grow.
If only the generic approach is used, the complexity would be reduced, but the performance for small needles would be worse, the generic approach for small needles and 64-bit elements even loses to the scalar implementation.
Benchmark results
Before:
After: