Skip to content

Commit 7f08da0

Browse files
committed
Update libcxx to 16 Feb 2025
``` [libc++] Fix initialization-order-fiasco with iostream.cpp constructors (#126995) [libc++] Fixes (|multi)_set spaceship operator. (#127326) [libc++] Move unused basic_string function definition to the dylib sources (#126219) [libc++] Avoid including <features.h> on arbitrary platforms (#125587) [libc++][format] Disables the FTM on older MacOS versions. (#126547) [libcxx] Add a missing include for __enable_if_t (#127016) [libcxx] Add a missing include for __bit_iterator (#127015) [libc++] Remove conditional for attributes that are always available (#126879) [libc++] Remove obsolete guards for join_view being experimental (#126697) [libc++] Extract destroy algorithms into separate headers (#126449) [libc++][chrono] implements TAI clock. (#125550) [libc++] Remove basic_string::__clear_and_shrink (#126050) [libc++] Support constexpr for std::stable_sort in radix sort branch (#125284) [libc++] Replace __is_trivially_relocatable by is_trivially_copyable (#124970) [lib++][Format] Updates Unicode database. (#125712) [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (#122410) [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839) [libc++] Fix stray usage of _LIBCPP_HAS_NO_WIDE_CHARACTERS on Windows [libc++][TZDB] Fixes %z escaping. (#125399) [libc++] Decrease instantiation cost of __constexpr_memmove (#125109) [libc++] Implement N4258(Cleaning-up noexcept in the Library) (#120312) [libc++] Optimize ranges::copy_backward for vector<bool>::iterator (#121026) [libc++] Optimize ranges::copy{, _n} for vector<bool>::iterator (#121013) [libc++] Refactor num_get optimization to not be ABI breaking (#121690) [libc++] Simplify the implementation of iostream.cpp (#124103) [libc++] Simplify vector<bool>::__construct_at_end (#119632) [libc++] Remove some private symbols from the ABI (#121497) [libcxx] Use _ftelli64/_fseeki64 on Windows (#123128) [libc++] Disable CFI in __libcpp_allocate (#124805) [libc++] Remove Android header no longer in use (#124691) [libc++] Add more missing bits to the locale base API (#122531) [libc++] implement std::flat_multimap (#113835) [libc++][format][3/3] Improves formatting performance. (#108990) [libc++] Reduce std::conjunction overhead (#124259) [libc++][chrono] implements UTC clock. (#90393) [libc++] Switch experimental library macros to 0/1 macros (#124030) [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (#118167) [libc++] Inline basic_streambuf functions (#123379) [libc++] Remove a few unused includes (#124025) [libc++] Remove support for Android 4 and older (#124062) [libc++] Avoid unnecessary instantiations for __copy_cvref_t (#123718) [libc++] Fix input-only range handling for vector (#116157) [libc++] Fix input-only range handling for basic_string (#116890) [libc++] Fix no-op shrink_to_fit for vector<bool> (#120495) [libc++] Another _LIBCPP_NODEBUG fix [libc++] Add missing _LIBCPP_NODEBUG on internal alias [libc++] Define an internal API for std::invoke and friends (#116637) [libc++] Fix vector sanitization annotations on destruction (#121031) [libc++] remove yield from atomic::wait (#120012) [libc++] Don't implement <stdatomic.h> before C++23 (#123130) [libc++] Enable _LIBCPP_NODEBUG again (#123318) [libc++] Simplify when the sized global deallocations overloads are available (#114667) ``` commit_hash:c4dee431e33408d110c123c1ea677d3897276e0e
1 parent 1a3600c commit 7f08da0

File tree

189 files changed

+3178
-2453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+3178
-2453
lines changed

build/sysincl/stl-to-libcxx.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,13 @@
468468
- __chrono/steady_clock.h: contrib/libs/cxxsupp/libcxx/include/__chrono/steady_clock.h
469469
- __chrono/sys_info.h: contrib/libs/cxxsupp/libcxx/include/__chrono/sys_info.h
470470
- __chrono/system_clock.h: contrib/libs/cxxsupp/libcxx/include/__chrono/system_clock.h
471+
- __chrono/tai_clock.h: contrib/libs/cxxsupp/libcxx/include/__chrono/tai_clock.h
471472
- __chrono/time_point.h: contrib/libs/cxxsupp/libcxx/include/__chrono/time_point.h
472473
- __chrono/time_zone.h: contrib/libs/cxxsupp/libcxx/include/__chrono/time_zone.h
473474
- __chrono/time_zone_link.h: contrib/libs/cxxsupp/libcxx/include/__chrono/time_zone_link.h
474475
- __chrono/tzdb.h: contrib/libs/cxxsupp/libcxx/include/__chrono/tzdb.h
475476
- __chrono/tzdb_list.h: contrib/libs/cxxsupp/libcxx/include/__chrono/tzdb_list.h
477+
- __chrono/utc_clock.h: contrib/libs/cxxsupp/libcxx/include/__chrono/utc_clock.h
476478
- __chrono/weekday.h: contrib/libs/cxxsupp/libcxx/include/__chrono/weekday.h
477479
- __chrono/year.h: contrib/libs/cxxsupp/libcxx/include/__chrono/year.h
478480
- __chrono/year_month.h: contrib/libs/cxxsupp/libcxx/include/__chrono/year_month.h
@@ -558,8 +560,11 @@
558560
- __filesystem/space_info.h: contrib/libs/cxxsupp/libcxx/include/__filesystem/space_info.h
559561
- __filesystem/u8path.h: contrib/libs/cxxsupp/libcxx/include/__filesystem/u8path.h
560562
- __flat_map/flat_map.h: contrib/libs/cxxsupp/libcxx/include/__flat_map/flat_map.h
563+
- __flat_map/flat_multimap.h: contrib/libs/cxxsupp/libcxx/include/__flat_map/flat_multimap.h
561564
- __flat_map/key_value_iterator.h: contrib/libs/cxxsupp/libcxx/include/__flat_map/key_value_iterator.h
565+
- __flat_map/sorted_equivalent.h: contrib/libs/cxxsupp/libcxx/include/__flat_map/sorted_equivalent.h
562566
- __flat_map/sorted_unique.h: contrib/libs/cxxsupp/libcxx/include/__flat_map/sorted_unique.h
567+
- __flat_map/utils.h: contrib/libs/cxxsupp/libcxx/include/__flat_map/utils.h
563568
- __format/buffer.h: contrib/libs/cxxsupp/libcxx/include/__format/buffer.h
564569
- __format/concepts.h: contrib/libs/cxxsupp/libcxx/include/__format/concepts.h
565570
- __format/container_adaptor.h: contrib/libs/cxxsupp/libcxx/include/__format/container_adaptor.h
@@ -747,13 +752,15 @@
747752
- __memory/compressed_pair.h: contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h
748753
- __memory/concepts.h: contrib/libs/cxxsupp/libcxx/include/__memory/concepts.h
749754
- __memory/construct_at.h: contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h
755+
- __memory/destroy.h: contrib/libs/cxxsupp/libcxx/include/__memory/destroy.h
750756
- __memory/destruct_n.h: contrib/libs/cxxsupp/libcxx/include/__memory/destruct_n.h
751757
- __memory/inout_ptr.h: contrib/libs/cxxsupp/libcxx/include/__memory/inout_ptr.h
752758
- __memory/noexcept_move_assign_container.h: contrib/libs/cxxsupp/libcxx/include/__memory/noexcept_move_assign_container.h
753759
- __memory/out_ptr.h: contrib/libs/cxxsupp/libcxx/include/__memory/out_ptr.h
754760
- __memory/pointer_safety.h: contrib/libs/cxxsupp/libcxx/include/__memory/pointer_safety.h
755761
- __memory/pointer_traits.h: contrib/libs/cxxsupp/libcxx/include/__memory/pointer_traits.h
756762
- __memory/ranges_construct_at.h: contrib/libs/cxxsupp/libcxx/include/__memory/ranges_construct_at.h
763+
- __memory/ranges_destroy.h: contrib/libs/cxxsupp/libcxx/include/__memory/ranges_destroy.h
757764
- __memory/ranges_uninitialized_algorithms.h: contrib/libs/cxxsupp/libcxx/include/__memory/ranges_uninitialized_algorithms.h
758765
- __memory/raw_storage_iterator.h: contrib/libs/cxxsupp/libcxx/include/__memory/raw_storage_iterator.h
759766
- __memory/shared_count.h: contrib/libs/cxxsupp/libcxx/include/__memory/shared_count.h

contrib/libs/cxxsupp/libcxx/include/__algorithm/copy.h

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#include <__algorithm/for_each_segment.h>
1414
#include <__algorithm/min.h>
1515
#include <__config>
16+
#include <__fwd/bit_reference.h>
1617
#include <__iterator/iterator_traits.h>
1718
#include <__iterator/segmented_iterator.h>
19+
#include <__memory/pointer_traits.h>
1820
#include <__type_traits/common_type.h>
1921
#include <__type_traits/enable_if.h>
2022
#include <__utility/move.h>
@@ -29,9 +31,129 @@ _LIBCPP_PUSH_MACROS
2931

3032
_LIBCPP_BEGIN_NAMESPACE_STD
3133

34+
template <class _InputIterator, class _OutputIterator>
35+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
36+
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result);
37+
3238
template <class _InIter, class _Sent, class _OutIter>
3339
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter);
3440

41+
template <class _Cp, bool _IsConst>
42+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_aligned(
43+
__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
44+
using _In = __bit_iterator<_Cp, _IsConst>;
45+
using difference_type = typename _In::difference_type;
46+
using __storage_type = typename _In::__storage_type;
47+
48+
const int __bits_per_word = _In::__bits_per_word;
49+
difference_type __n = __last - __first;
50+
if (__n > 0) {
51+
// do first word
52+
if (__first.__ctz_ != 0) {
53+
unsigned __clz = __bits_per_word - __first.__ctz_;
54+
difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
55+
__n -= __dn;
56+
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
57+
__storage_type __b = *__first.__seg_ & __m;
58+
*__result.__seg_ &= ~__m;
59+
*__result.__seg_ |= __b;
60+
__result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
61+
__result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
62+
++__first.__seg_;
63+
// __first.__ctz_ = 0;
64+
}
65+
// __first.__ctz_ == 0;
66+
// do middle words
67+
__storage_type __nw = __n / __bits_per_word;
68+
std::copy(std::__to_address(__first.__seg_),
69+
std::__to_address(__first.__seg_ + __nw),
70+
std::__to_address(__result.__seg_));
71+
__n -= __nw * __bits_per_word;
72+
__result.__seg_ += __nw;
73+
// do last word
74+
if (__n > 0) {
75+
__first.__seg_ += __nw;
76+
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
77+
__storage_type __b = *__first.__seg_ & __m;
78+
*__result.__seg_ &= ~__m;
79+
*__result.__seg_ |= __b;
80+
__result.__ctz_ = static_cast<unsigned>(__n);
81+
}
82+
}
83+
return __result;
84+
}
85+
86+
template <class _Cp, bool _IsConst>
87+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_unaligned(
88+
__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
89+
using _In = __bit_iterator<_Cp, _IsConst>;
90+
using difference_type = typename _In::difference_type;
91+
using __storage_type = typename _In::__storage_type;
92+
93+
const int __bits_per_word = _In::__bits_per_word;
94+
difference_type __n = __last - __first;
95+
if (__n > 0) {
96+
// do first word
97+
if (__first.__ctz_ != 0) {
98+
unsigned __clz_f = __bits_per_word - __first.__ctz_;
99+
difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
100+
__n -= __dn;
101+
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
102+
__storage_type __b = *__first.__seg_ & __m;
103+
unsigned __clz_r = __bits_per_word - __result.__ctz_;
104+
__storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
105+
__m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
106+
*__result.__seg_ &= ~__m;
107+
if (__result.__ctz_ > __first.__ctz_)
108+
*__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_);
109+
else
110+
*__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_);
111+
__result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
112+
__result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
113+
__dn -= __ddn;
114+
if (__dn > 0) {
115+
__m = ~__storage_type(0) >> (__bits_per_word - __dn);
116+
*__result.__seg_ &= ~__m;
117+
*__result.__seg_ |= __b >> (__first.__ctz_ + __ddn);
118+
__result.__ctz_ = static_cast<unsigned>(__dn);
119+
}
120+
++__first.__seg_;
121+
// __first.__ctz_ = 0;
122+
}
123+
// __first.__ctz_ == 0;
124+
// do middle words
125+
unsigned __clz_r = __bits_per_word - __result.__ctz_;
126+
__storage_type __m = ~__storage_type(0) << __result.__ctz_;
127+
for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) {
128+
__storage_type __b = *__first.__seg_;
129+
*__result.__seg_ &= ~__m;
130+
*__result.__seg_ |= __b << __result.__ctz_;
131+
++__result.__seg_;
132+
*__result.__seg_ &= __m;
133+
*__result.__seg_ |= __b >> __clz_r;
134+
}
135+
// do last word
136+
if (__n > 0) {
137+
__m = ~__storage_type(0) >> (__bits_per_word - __n);
138+
__storage_type __b = *__first.__seg_ & __m;
139+
__storage_type __dn = std::min(__n, static_cast<difference_type>(__clz_r));
140+
__m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
141+
*__result.__seg_ &= ~__m;
142+
*__result.__seg_ |= __b << __result.__ctz_;
143+
__result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
144+
__result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
145+
__n -= __dn;
146+
if (__n > 0) {
147+
__m = ~__storage_type(0) >> (__bits_per_word - __n);
148+
*__result.__seg_ &= ~__m;
149+
*__result.__seg_ |= __b >> __dn;
150+
__result.__ctz_ = static_cast<unsigned>(__n);
151+
}
152+
}
153+
}
154+
return __result;
155+
}
156+
35157
struct __copy_impl {
36158
template <class _InIter, class _Sent, class _OutIter>
37159
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
@@ -95,6 +217,16 @@ struct __copy_impl {
95217
}
96218
}
97219

220+
template <class _Cp, bool _IsConst>
221+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
222+
operator()(__bit_iterator<_Cp, _IsConst> __first,
223+
__bit_iterator<_Cp, _IsConst> __last,
224+
__bit_iterator<_Cp, false> __result) const {
225+
if (__first.__ctz_ == __result.__ctz_)
226+
return std::make_pair(__last, std::__copy_aligned(__first, __last, __result));
227+
return std::make_pair(__last, std::__copy_unaligned(__first, __last, __result));
228+
}
229+
98230
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
99231
template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
100232
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
@@ -110,7 +242,7 @@ __copy(_InIter __first, _Sent __last, _OutIter __result) {
110242
}
111243

112244
template <class _InputIterator, class _OutputIterator>
113-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
245+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
114246
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
115247
return std::__copy(__first, __last, __result).second;
116248
}

contrib/libs/cxxsupp/libcxx/include/__algorithm/copy_backward.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
1111

1212
#include <__algorithm/copy_move_common.h>
13+
#include <__algorithm/copy_n.h>
1314
#include <__algorithm/iterator_operations.h>
1415
#include <__algorithm/min.h>
1516
#include <__config>
17+
#include <__fwd/bit_reference.h>
1618
#include <__iterator/iterator_traits.h>
1719
#include <__iterator/segmented_iterator.h>
20+
#include <__memory/pointer_traits.h>
1821
#include <__type_traits/common_type.h>
1922
#include <__type_traits/enable_if.h>
2023
#include <__type_traits/is_constructible.h>
@@ -34,6 +37,124 @@ template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
3437
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter>
3538
__copy_backward(_InIter __first, _Sent __last, _OutIter __result);
3639

40+
template <class _Cp, bool _IsConst>
41+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_aligned(
42+
__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
43+
using _In = __bit_iterator<_Cp, _IsConst>;
44+
using difference_type = typename _In::difference_type;
45+
using __storage_type = typename _In::__storage_type;
46+
47+
const int __bits_per_word = _In::__bits_per_word;
48+
difference_type __n = __last - __first;
49+
if (__n > 0) {
50+
// do first word
51+
if (__last.__ctz_ != 0) {
52+
difference_type __dn = std::min(static_cast<difference_type>(__last.__ctz_), __n);
53+
__n -= __dn;
54+
unsigned __clz = __bits_per_word - __last.__ctz_;
55+
__storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz);
56+
__storage_type __b = *__last.__seg_ & __m;
57+
*__result.__seg_ &= ~__m;
58+
*__result.__seg_ |= __b;
59+
__result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
60+
// __last.__ctz_ = 0
61+
}
62+
// __last.__ctz_ == 0 || __n == 0
63+
// __result.__ctz_ == 0 || __n == 0
64+
// do middle words
65+
__storage_type __nw = __n / __bits_per_word;
66+
__result.__seg_ -= __nw;
67+
__last.__seg_ -= __nw;
68+
std::copy_n(std::__to_address(__last.__seg_), __nw, std::__to_address(__result.__seg_));
69+
__n -= __nw * __bits_per_word;
70+
// do last word
71+
if (__n > 0) {
72+
__storage_type __m = ~__storage_type(0) << (__bits_per_word - __n);
73+
__storage_type __b = *--__last.__seg_ & __m;
74+
*--__result.__seg_ &= ~__m;
75+
*__result.__seg_ |= __b;
76+
__result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
77+
}
78+
}
79+
return __result;
80+
}
81+
82+
template <class _Cp, bool _IsConst>
83+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_unaligned(
84+
__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
85+
using _In = __bit_iterator<_Cp, _IsConst>;
86+
using difference_type = typename _In::difference_type;
87+
using __storage_type = typename _In::__storage_type;
88+
89+
const int __bits_per_word = _In::__bits_per_word;
90+
difference_type __n = __last - __first;
91+
if (__n > 0) {
92+
// do first word
93+
if (__last.__ctz_ != 0) {
94+
difference_type __dn = std::min(static_cast<difference_type>(__last.__ctz_), __n);
95+
__n -= __dn;
96+
unsigned __clz_l = __bits_per_word - __last.__ctz_;
97+
__storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l);
98+
__storage_type __b = *__last.__seg_ & __m;
99+
unsigned __clz_r = __bits_per_word - __result.__ctz_;
100+
__storage_type __ddn = std::min(__dn, static_cast<difference_type>(__result.__ctz_));
101+
if (__ddn > 0) {
102+
__m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r);
103+
*__result.__seg_ &= ~__m;
104+
if (__result.__ctz_ > __last.__ctz_)
105+
*__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
106+
else
107+
*__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_);
108+
__result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
109+
__dn -= __ddn;
110+
}
111+
if (__dn > 0) {
112+
// __result.__ctz_ == 0
113+
--__result.__seg_;
114+
__result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1));
115+
__m = ~__storage_type(0) << __result.__ctz_;
116+
*__result.__seg_ &= ~__m;
117+
__last.__ctz_ -= __dn + __ddn;
118+
*__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
119+
}
120+
// __last.__ctz_ = 0
121+
}
122+
// __last.__ctz_ == 0 || __n == 0
123+
// __result.__ctz_ != 0 || __n == 0
124+
// do middle words
125+
unsigned __clz_r = __bits_per_word - __result.__ctz_;
126+
__storage_type __m = ~__storage_type(0) >> __clz_r;
127+
for (; __n >= __bits_per_word; __n -= __bits_per_word) {
128+
__storage_type __b = *--__last.__seg_;
129+
*__result.__seg_ &= ~__m;
130+
*__result.__seg_ |= __b >> __clz_r;
131+
*--__result.__seg_ &= __m;
132+
*__result.__seg_ |= __b << __result.__ctz_;
133+
}
134+
// do last word
135+
if (__n > 0) {
136+
__m = ~__storage_type(0) << (__bits_per_word - __n);
137+
__storage_type __b = *--__last.__seg_ & __m;
138+
__clz_r = __bits_per_word - __result.__ctz_;
139+
__storage_type __dn = std::min(__n, static_cast<difference_type>(__result.__ctz_));
140+
__m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r);
141+
*__result.__seg_ &= ~__m;
142+
*__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_);
143+
__result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
144+
__n -= __dn;
145+
if (__n > 0) {
146+
// __result.__ctz_ == 0
147+
--__result.__seg_;
148+
__result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
149+
__m = ~__storage_type(0) << __result.__ctz_;
150+
*__result.__seg_ &= ~__m;
151+
*__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn));
152+
}
153+
}
154+
}
155+
return __result;
156+
}
157+
37158
template <class _AlgPolicy>
38159
struct __copy_backward_impl {
39160
template <class _InIter, class _Sent, class _OutIter>
@@ -107,6 +228,16 @@ struct __copy_backward_impl {
107228
}
108229
}
109230

231+
template <class _Cp, bool _IsConst>
232+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
233+
operator()(__bit_iterator<_Cp, _IsConst> __first,
234+
__bit_iterator<_Cp, _IsConst> __last,
235+
__bit_iterator<_Cp, false> __result) {
236+
if (__last.__ctz_ == __result.__ctz_)
237+
return std::make_pair(__last, std::__copy_backward_aligned(__first, __last, __result));
238+
return std::make_pair(__last, std::__copy_backward_unaligned(__first, __last, __result));
239+
}
240+
110241
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
111242
template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
112243
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>

0 commit comments

Comments
 (0)