Vectorize find_first_of for 8 and 16 bit elements with SSE4.2 pcmpestri#4466
Merged
StephanTLavavej merged 18 commits intomicrosoft:mainfrom Mar 21, 2024
Merged
Vectorize find_first_of for 8 and 16 bit elements with SSE4.2 pcmpestri#4466StephanTLavavej merged 18 commits intomicrosoft:mainfrom
find_first_of for 8 and 16 bit elements with SSE4.2 pcmpestri#4466StephanTLavavej merged 18 commits intomicrosoft:mainfrom
Conversation
Contributor
|
As we discovered on Discord a while ago, some people call std::find_first_of with a single-element needle. This should be forwarded to std::find (or memchr or something), even if vectorization is otherwise disabled. |
Contributor
Author
I remember this, but it is so much unrelated, that I think it better fits a separate PR |
StephanTLavavej
requested changes
Mar 20, 2024
StephanTLavavej
approved these changes
Mar 21, 2024
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
|
Thanks for vectorizing more algorithms! 🚀 ⏩ 🎉 |
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.
Suggested by @Alcaro in #4415 (comment)
For element set that fits SSE register, that is length of "needle" is up to 16 for 8-bit element, up to 8 for 16-bit element
Possible future work:
findinstead for 1-element cases as @Alcaro suggestedbasic_string::find_first_of. Certainly not the general case with user-provided char traits, but maybe for standard cases;Benchmark result
The first non-type template parameter in the benchmark results is the position where the value is found, "haystack" length is twice that.
The second non-type template parameter in the benchmark results is the "needle" size.
Before:
After:
Explanation:
bm<uint8_t, 9, 3>row, the vectorization is engaged;bm<uint8_t, 22, 5>already shows significant improvement;bm<uint16_t, 1011, 11>falls back to the scalar algorithm due to "needle" length not fitting SSE register.