You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let in a wider variety of element types that are eligible to be processed by branchless sort functions, like POD structs and pointers.
This change causes `sort_stability.pass.cpp` to prefer branchless sort for `EqualType`, but not if the comparator is an arbitrary lambda.
So the test is adjusted to always pass a simple comparator. `nth_element_stability.pass.cpp` and `partial_sort_stability.pass.cpp` already
use a simple comparator all the time, so they don't need to be adjusted.
We considered forbidding the branchless version for unintentionally
expensive comparators, e.g.
double a[10]; std::sort(a, a+10, std::less<BigDouble>());
Derived *a[10]; std::sort(a, a+10, std::less<VirtualBase*>());
In both cases, it is safe, but more expensive than the original PR
intended (since the comparator will be invoked more often in the branchless
version). However, it's invoked only 0.1% more often, and benchmarks show
that the branchless version is still (much) faster despite the extra
invocations. So we leave this alone.
Sample benchmarks:
- https://godbolt.org/z/x1Waz3vbY
- https://godbolt.org/z/5Ph3hfqbc
Sanity-check that "branchless sort" is used only for trivially copyable types
It relies on copying the elements, so copying must be at least possible,
and ideally no more expensive than move; i.e., trivial. No functional change.
0 commit comments