Skip to content

Commit 75ea131

Browse files
committed
[libc++] Optimize num_get integral functions
1 parent 3b10b9a commit 75ea131

File tree

21 files changed

+303
-411
lines changed

21 files changed

+303
-411
lines changed

libcxx/docs/ReleaseNotes/21.rst

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

7373
- The ``num_put::do_put`` integral overloads have been optimized, resulting in a performance improvement of up to 2.4x.
7474

75+
- The ``num_get::do_get`` integral overloads have been optimized, resulting in a performance improvement of up to 2.8x.
76+
7577
- The ``std::stable_sort`` algorithm uses radix sort for floating-point types now, which can improve the performance
7678
up to 10x, depending on type of sorted elements and the initial state of the sorted array.
7779

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ set(files
516516
__locale_dir/locale_base_api.h
517517
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
518518
__locale_dir/locale_base_api/ibm.h
519-
__locale_dir/locale_base_api/musl.h
520519
__locale_dir/locale_base_api/openbsd.h
521520
__locale_dir/messages.h
522521
__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,11 +114,37 @@ 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 __all_of(__simd_vector<_Tp, _Np> __vec) noexcept {
119140
return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
120141
}
121142

143+
template <class _Tp, size_t _Np>
144+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __none_of(__simd_vector<_Tp, _Np> __vec) noexcept {
145+
return !__builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
146+
}
147+
122148
template <class _Tp, size_t _Np>
123149
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept {
124150
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
@@ -131,8 +128,6 @@
131128
# include <__locale_dir/locale_base_api/ibm.h>
132129
# elif defined(__OpenBSD__)
133130
# include <__locale_dir/locale_base_api/openbsd.h>
134-
# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
135-
# include <__locale_dir/locale_base_api/musl.h>
136131
# endif
137132

138133
# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
@@ -192,15 +187,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
192187
return strtold_l(__nptr, __endptr, __loc);
193188
}
194189

195-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
196-
return strtoll_l(__nptr, __endptr, __base, __loc);
197-
}
198-
199-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
200-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
201-
return strtoull_l(__nptr, __endptr, __base, __loc);
202-
}
203-
204190
//
205191
// Character manipulation functions
206192
//
@@ -302,11 +288,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __
302288
char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
303289
return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
304290
}
305-
template <class... _Args>
306-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
307-
const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
308-
return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
309-
}
310291
_LIBCPP_DIAGNOSTIC_POP
311292
# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
312293

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)