Skip to content

Commit 6ab488f

Browse files
committed
[libc++] Optimize num_get integral functions
1 parent 8ea447b commit 6ab488f

File tree

21 files changed

+402
-412
lines changed

21 files changed

+402
-412
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Improvements and New Features
8080
iterators, resulting in a performance improvement for ``std::deque<short>`` and
8181
``std::join_view<vector<vector<short>>>`` iterators.
8282

83+
- The ``num_get::do_get`` integral overloads have been optimized, resulting in a performance improvement of up to 2.8x.
84+
8385
Deprecations and Removals
8486
-------------------------
8587

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ set(files
517517
__locale_dir/locale_base_api.h
518518
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
519519
__locale_dir/locale_base_api/ibm.h
520-
__locale_dir/locale_base_api/musl.h
521520
__locale_dir/locale_base_api/openbsd.h
522521
__locale_dir/messages.h
523522
__locale_dir/money.h

libcxx/include/__algorithm/simd_utils.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,27 @@ template <class _VecT, class _Iter>
114114
}(make_index_sequence<__simd_vector_size_v<_VecT>>{});
115115
}
116116

117+
// Load the first _Np elements, zero the rest
118+
_LIBCPP_DIAGNOSTIC_PUSH
119+
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi")
120+
template <class _VecT, size_t _Np, class _Iter>
121+
[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __partial_load(_Iter __iter) noexcept {
122+
return [=]<size_t... _LoadIndices, size_t... _ZeroIndices>(
123+
index_sequence<_LoadIndices...>, index_sequence<_ZeroIndices...>) _LIBCPP_ALWAYS_INLINE noexcept {
124+
return _VecT{__iter[_LoadIndices]..., ((void)_ZeroIndices, 0)...};
125+
}(make_index_sequence<_Np>{}, make_index_sequence<__simd_vector_size_v<_VecT> - _Np>{});
126+
}
127+
128+
// Create a vector where every elements is __val
129+
template <class _VecT>
130+
[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT
131+
__broadcast(__simd_vector_underlying_type_t<_VecT> __val) {
132+
return [&]<std::size_t... _Indices>(index_sequence<_Indices...>) {
133+
return _VecT{((void)_Indices, __val)...};
134+
}(make_index_sequence<__simd_vector_size_v<_VecT>>());
135+
}
136+
_LIBCPP_DIAGNOSTIC_POP
137+
117138
template <class _Tp, size_t _Np>
118139
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __any_of(__simd_vector<_Tp, _Np> __vec) noexcept {
119140
return __builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
@@ -124,6 +145,11 @@ template <class _Tp, size_t _Np>
124145
return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
125146
}
126147

148+
template <class _Tp, size_t _Np>
149+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __none_of(__simd_vector<_Tp, _Np> __vec) noexcept {
150+
return !__builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
151+
}
152+
127153
template <class _Tp, size_t _Np>
128154
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept {
129155
using __mask_vec = __simd_vector<bool, _Np>;

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
// float __strtof(const char*, char**, __locale_t);
5858
// double __strtod(const char*, char**, __locale_t);
5959
// long double __strtold(const char*, char**, __locale_t);
60-
// long long __strtoll(const char*, char**, __locale_t);
61-
// unsigned long long __strtoull(const char*, char**, __locale_t);
6260
// }
6361
//
6462
// Character manipulation functions
@@ -106,7 +104,6 @@
106104
//
107105
// int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
108106
// int __asprintf(char**, __locale_t, const char*, ...); // required by the headers
109-
// int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers
110107
// }
111108

112109
#if _LIBCPP_HAS_LOCALIZATION
@@ -133,8 +130,6 @@
133130
# include <__locale_dir/locale_base_api/ibm.h>
134131
# elif defined(__OpenBSD__)
135132
# include <__locale_dir/locale_base_api/openbsd.h>
136-
# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
137-
# include <__locale_dir/locale_base_api/musl.h>
138133
# endif
139134

140135
# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
@@ -194,15 +189,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
194189
return strtold_l(__nptr, __endptr, __loc);
195190
}
196191

197-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
198-
return strtoll_l(__nptr, __endptr, __base, __loc);
199-
}
200-
201-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
202-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
203-
return strtoull_l(__nptr, __endptr, __base, __loc);
204-
}
205-
206192
//
207193
// Character manipulation functions
208194
//
@@ -304,11 +290,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __
304290
char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
305291
return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
306292
}
307-
template <class... _Args>
308-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
309-
const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
310-
return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
311-
}
312293
_LIBCPP_DIAGNOSTIC_POP
313294
# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
314295

libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,6 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
125125
return __res;
126126
}
127127

128-
inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
129-
const char* __s, locale_t __l, const char* __format, ...) {
130-
va_list __va;
131-
va_start(__va, __format);
132-
__locale_guard __current(__l);
133-
int __res = vsscanf(__s, __format, __va);
134-
va_end(__va);
135-
return __res;
136-
}
137-
138128
_LIBCPP_END_NAMESPACE_STD
139129

140130
#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H

libcxx/include/__locale_dir/locale_base_api/ibm.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ struct __setAndRestore {
5353

5454
// The following are not POSIX routines. These are quick-and-dirty hacks
5555
// to make things pretend to work
56-
inline _LIBCPP_HIDE_FROM_ABI long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
57-
__setAndRestore __newloc(locale);
58-
return ::strtoll(__nptr, __endptr, __base);
59-
}
60-
6156
inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t locale) {
6257
__setAndRestore __newloc(locale);
6358
return ::strtod(__nptr, __endptr);
@@ -73,12 +68,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __
7368
return ::strtold(__nptr, __endptr);
7469
}
7570

76-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
77-
strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
78-
__setAndRestore __newloc(locale);
79-
return ::strtoull(__nptr, __endptr, __base);
80-
}
81-
8271
inline _LIBCPP_HIDE_FROM_ABI
8372
_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) {
8473
const size_t buff_size = 256;

libcxx/include/__locale_dir/locale_base_api/musl.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)