1349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
981ad6265SDimitry Andric #include <algorithm>
1006c3fb27SDimitry Andric #include <bit>
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
130b57cec5SDimitry Andric 
1406c3fb27SDimitry Andric template <class Comp, class RandomAccessIterator>
__sort(RandomAccessIterator first,RandomAccessIterator last,Comp comp)1506c3fb27SDimitry Andric void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
1606c3fb27SDimitry Andric   auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));
1781ad6265SDimitry Andric 
1806c3fb27SDimitry Andric   // Only use bitset partitioning for arithmetic types.  We should also check
1906c3fb27SDimitry Andric   // that the default comparator is in use so that we are sure that there are no
2006c3fb27SDimitry Andric   // branches in the comparator.
2106c3fb27SDimitry Andric   std::__introsort<_ClassicAlgPolicy,
2206c3fb27SDimitry Andric                    ranges::less,
2306c3fb27SDimitry Andric                    RandomAccessIterator,
2406c3fb27SDimitry Andric                    __use_branchless_sort<ranges::less, RandomAccessIterator>::value>(
2506c3fb27SDimitry Andric       first, last, ranges::less{}, depth_limit);
2606c3fb27SDimitry Andric }
2706c3fb27SDimitry Andric 
2806c3fb27SDimitry Andric // clang-format off
290b57cec5SDimitry Andric template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
30349cc55cSDimitry Andric #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
310b57cec5SDimitry Andric template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
32349cc55cSDimitry Andric #endif
330b57cec5SDimitry Andric template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
340b57cec5SDimitry Andric template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
350b57cec5SDimitry Andric template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
360b57cec5SDimitry Andric template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
370b57cec5SDimitry Andric template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
380b57cec5SDimitry Andric template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
390b57cec5SDimitry Andric template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
400b57cec5SDimitry Andric template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
410b57cec5SDimitry Andric template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
420b57cec5SDimitry Andric template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
430b57cec5SDimitry Andric template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
440b57cec5SDimitry Andric template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
450b57cec5SDimitry Andric template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
4606c3fb27SDimitry Andric // clang-format on
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric _LIBCPP_END_NAMESPACE_STD
49