Skip to content

Commit 4a99b3e

Browse files
committed
[libc++] Optimize num_get integral functions
1 parent 956cfa6 commit 4a99b3e

File tree

7 files changed

+191
-181
lines changed

7 files changed

+191
-181
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Improvements and New Features
120120

121121
- Added :ref:`hardening mode <hardening>` support for ``forward_list`` and ``bitset``.
122122

123+
- The ``num_get::do_get`` integral overloads have been optimized. resulting in a performance improvement of up to 2.8x.
124+
123125
Deprecations and Removals
124126
-------------------------
125127

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 <class _Tp, size_t _Np>
120140
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept {
121141
return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
122142
}
123143

144+
template <class _Tp, size_t _Np>
145+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __none_of(__simd_vector<_Tp, _Np> __vec) noexcept {
146+
return !__builtin_reduce_or(__vec);
147+
}
148+
124149
template <class _Tp, size_t _Np>
125150
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept {
126151
using __mask_vec = __simd_vector<bool, _Np>;

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
// float __strtof(const char*, char**, __locale_t);
5252
// double __strtod(const char*, char**, __locale_t);
5353
// long double __strtold(const char*, char**, __locale_t);
54-
// long long __strtoll(const char*, char**, __locale_t);
55-
// unsigned long long __strtoull(const char*, char**, __locale_t);
5654
// }
5755
//
5856
// Character manipulation functions
@@ -182,15 +180,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
182180
return strtold_l(__nptr, __endptr, __loc);
183181
}
184182

185-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
186-
return strtoll_l(__nptr, __endptr, __base, __loc);
187-
}
188-
189-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
190-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
191-
return strtoull_l(__nptr, __endptr, __base, __loc);
192-
}
193-
194183
//
195184
// Character manipulation functions
196185
//

libcxx/include/__locale_dir/support/bsd_like.h

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

78-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
79-
return ::strtoll_l(__nptr, __endptr, __base, __loc);
80-
}
81-
82-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
83-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
84-
return ::strtoull_l(__nptr, __endptr, __base, __loc);
85-
}
86-
8778
//
8879
// Character manipulation functions
8980
//

libcxx/include/__locale_dir/support/windows.h

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

187-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
188-
return ::_strtoi64_l(__nptr, __endptr, __base, __loc);
189-
}
190-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
191-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
192-
return ::_strtoui64_l(__nptr, __endptr, __base, __loc);
193-
}
194-
195187
//
196188
// Character manipulation functions
197189
//

0 commit comments

Comments
 (0)