Skip to content

Commit b466dc6

Browse files
committed
[libc++] Optimize num_get integral functions
1 parent 976f3a0 commit b466dc6

File tree

9 files changed

+221
-216
lines changed

9 files changed

+221
-216
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Improvements and New Features
7373
optimized, resulting in a performance improvement of up to 2x for trivial element types (e.g., `std::vector<int>`),
7474
and up to 3.4x for non-trivial element types (e.g., `std::vector<std::vector<int>>`).
7575

76+
- The ``num_get::do_get`` integral overloads have been optimized. resulting in a performance improvement of up to 2.8x.
77+
7678
Deprecations and Removals
7779
-------------------------
7880

libcxx/include/__algorithm/simd_utils.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,36 @@ template <class _VecT, class _Iter>
116116
}(make_index_sequence<__simd_vector_size_v<_VecT>>{});
117117
}
118118

119+
// Load the first _Np elements, zero the rest
120+
_LIBCPP_DIAGNOSTIC_PUSH
121+
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi")
122+
template <class _VecT, size_t _Np, class _Iter>
123+
[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __partial_load(_Iter __iter) noexcept {
124+
return [=]<size_t... _LoadIndices, size_t... _ZeroIndices>(
125+
index_sequence<_LoadIndices...>, index_sequence<_ZeroIndices...>) _LIBCPP_ALWAYS_INLINE noexcept {
126+
return _VecT{__iter[_LoadIndices]...};
127+
}(make_index_sequence<_Np>{}, make_index_sequence<__simd_vector_size_v<_VecT> - _Np>{});
128+
}
129+
130+
template <class _VecT>
131+
[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT
132+
__broadcast(__simd_vector_underlying_type_t<_VecT> __val) {
133+
return [&]<std::size_t... _Indices>(index_sequence<_Indices...>) {
134+
return _VecT{((void)_Indices, __val)...};
135+
}(make_index_sequence<__simd_vector_size_v<_VecT>>());
136+
}
137+
_LIBCPP_DIAGNOSTIC_POP
138+
119139
template <size_t _Np>
120140
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<bool, _Np> __vec) noexcept {
121141
return __builtin_reduce_and(__vec);
122142
}
123143

144+
template <size_t _Np>
145+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __none_of(__simd_vector<bool, _Np> __vec) noexcept {
146+
return !__builtin_reduce_or(__vec);
147+
}
148+
124149
template <class _Tp, size_t _Np>
125150
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI auto __as_mask(__simd_vector<_Tp, _Np> __vec) noexcept {
126151
static_assert(!is_same<_Tp, bool>::value, "vector type should not be a bool!");

libcxx/include/__configuration/abi.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
// because it changes the mangling of the virtual function located in the vtable, which
5858
// changes how it gets signed.
5959
# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
60-
// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
61-
# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
6260
// Give reverse_iterator<T> one data member of type T, not two.
6361
// Also, in C++17 and later, don't derive iterator types from std::iterator.
6462
# define _LIBCPP_ABI_NO_ITERATOR_BASES

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
// float __strtof(const char*, char**, __locale_t);
4141
// double __strtod(const char*, char**, __locale_t);
4242
// long double __strtold(const char*, char**, __locale_t);
43-
// long long __strtoll(const char*, char**, __locale_t);
44-
// unsigned long long __strtoull(const char*, char**, __locale_t);
4543
// }
4644
//
4745
// Character manipulation functions
@@ -160,15 +158,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
160158
return strtold_l(__nptr, __endptr, __loc);
161159
}
162160

163-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
164-
return strtoll_l(__nptr, __endptr, __base, __loc);
165-
}
166-
167-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
168-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
169-
return strtoull_l(__nptr, __endptr, __base, __loc);
170-
}
171-
172161
//
173162
// Character manipulation functions
174163
//

libcxx/include/__locale_dir/support/bsd_like.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
6161
return ::strtold_l(__nptr, __endptr, __loc);
6262
}
6363

64-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
65-
return ::strtoll_l(__nptr, __endptr, __base, __loc);
66-
}
67-
68-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
69-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
70-
return ::strtoull_l(__nptr, __endptr, __base, __loc);
71-
}
72-
7364
//
7465
// Character manipulation functions
7566
//

libcxx/include/__locale_dir/support/windows.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,6 @@ inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr
174174
return ::_strtod_l(__nptr, __endptr, __loc);
175175
}
176176

177-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
178-
return ::_strtoi64_l(__nptr, __endptr, __base, __loc);
179-
}
180-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
181-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
182-
return ::_strtoui64_l(__nptr, __endptr, __base, __loc);
183-
}
184-
185177
//
186178
// Character manipulation functions
187179
//

0 commit comments

Comments
 (0)