KEMBAR78
Vectorize equality-comparing algorithms for more types by AlexGuteniev · Pull Request #5527 · microsoft/STL · GitHub
Skip to content

Conversation

AlexGuteniev
Copy link
Contributor

@AlexGuteniev AlexGuteniev commented May 19, 2025

Towards #5479

Use __is_trivially_equality_comparable starting in Clang 19, with escape hatch.
Distinguish memcmp and search-like vector algorithms, as the latter need 1, 2, 4, or 8 element size.

If this takes on, may improve mismatch to vectorize for odd element size too.
It takes division, but it can be done in the header, where it will be optimized to big multiplication.

Also can look into _Vector_alg_in_find_is_safe.


I'm not sure though:

  • We can't have enums with this actually https://godbolt.org/z/33bsEvq1b
  • For structs need defaulted operator==
    • Which means pair<int, int> or chrono::duration<uint64_t, pico> will not be automatically engaged
  • On the other hand, here came member object pointer and member function pointer, which weren't invited actually
  • This all works for Clang only, making Clang behavior w.r.t. vectorization very different

Also drop _Vector_alg_in_find_first_of_is_safe in favor of _Vector_alg_in_search_is_safe
@AlexGuteniev AlexGuteniev requested a review from a team as a code owner May 19, 2025 18:52
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews May 19, 2025
@AlexGuteniev AlexGuteniev force-pushed the can-of-vectorization branch 2 times, most recently from 30600f3 to 14706e0 Compare May 19, 2025 19:16
@AlexGuteniev AlexGuteniev force-pushed the can-of-vectorization branch from 14706e0 to ab6be2d Compare May 19, 2025 19:58
@StephanTLavavej StephanTLavavej added the performance Must go faster label May 19, 2025
@StephanTLavavej StephanTLavavej self-assigned this May 19, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews May 20, 2025
@StephanTLavavej StephanTLavavej removed their assignment May 20, 2025
@StephanTLavavej
Copy link
Member

Thanks! 😻 I fixed typos and pushed minor nitpicks.

@AlexGuteniev AlexGuteniev changed the title Vectorize equality-comparing algorithms for more types Optimize equal and ranges::equal using memcmp for more types May 21, 2025
@AlexGuteniev
Copy link
Contributor Author

I've updated the title to a more specific.
There's actually just one of "equality-comparing algorithms": std::equal and its ranges version.

@AlexGuteniev AlexGuteniev changed the title Optimize equal and ranges::equal using memcmp for more types Vectorize equality-comparing algorithms for more types May 21, 2025
@AlexGuteniev
Copy link
Contributor Author

I've updated the title to a more specific. There's actually just one of "equality-comparing algorithms": std::equal and its ranges version.

Actually, restored previous title. search etc will be also optimized for the right struct size.

@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews May 22, 2025
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 3da7d27 into microsoft:main May 22, 2025
40 checks passed
@github-project-automation github-project-automation bot moved this from Merging to Done in STL Code Reviews May 22, 2025
@StephanTLavavej
Copy link
Member

Thanks for supporting Clang as even more of a first-class citizen than MSVC! 😹 🥇 🎉

@AlexGuteniev AlexGuteniev deleted the can-of-vectorization branch May 22, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants