Skip to content

Commit 9f61a94

Browse files
committed
[libc++] Optimize num_get integral functions
1 parent 1adb001 commit 9f61a94

File tree

17 files changed

+255
-416
lines changed

17 files changed

+255
-416
lines changed

libcxx/docs/ReleaseNotes/21.rst

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

5353
- Updated formatting library to Unicode 16.0.0.
5454

55+
- The ``num_get::do_get`` integral overloads have been optimized, resulting in a performance improvement of up to 2.8x.
56+
5557
Deprecations and Removals
5658
-------------------------
5759

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ set(files
506506
__locale_dir/locale_base_api/android.h
507507
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
508508
__locale_dir/locale_base_api/ibm.h
509-
__locale_dir/locale_base_api/musl.h
510509
__locale_dir/locale_base_api/openbsd.h
511510
__locale_dir/pad_and_output.h
512511
__locale_dir/support/apple.h

libcxx/include/__algorithm/simd_utils.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,37 @@ 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]..., ((void)_ZeroIndices, 0)...};
127+
}(make_index_sequence<_Np>{}, make_index_sequence<__simd_vector_size_v<_VecT> - _Np>{});
128+
}
129+
130+
// Create a vector where every elements is __val
131+
template <class _VecT>
132+
[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT
133+
__broadcast(__simd_vector_underlying_type_t<_VecT> __val) {
134+
return [&]<std::size_t... _Indices>(index_sequence<_Indices...>) {
135+
return _VecT{((void)_Indices, __val)...};
136+
}(make_index_sequence<__simd_vector_size_v<_VecT>>());
137+
}
138+
_LIBCPP_DIAGNOSTIC_POP
139+
119140
template <class _Tp, size_t _Np>
120141
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept {
121142
return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
122143
}
123144

145+
template <class _Tp, size_t _Np>
146+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __none_of(__simd_vector<_Tp, _Np> __vec) noexcept {
147+
return !__builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
148+
}
149+
124150
template <class _Tp, size_t _Np>
125151
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept {
126152
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
@@ -108,7 +106,6 @@
108106
//
109107
// int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
110108
// int __asprintf(char**, __locale_t, const char*, ...); // required by the headers
111-
// int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers
112109
// }
113110

114111
#if defined(__APPLE__)
@@ -133,8 +130,6 @@
133130
# include <__locale_dir/locale_base_api/android.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
//
@@ -309,11 +295,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __
309295
char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
310296
return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
311297
}
312-
template <class... _Args>
313-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
314-
const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
315-
return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
316-
}
317298
_LIBCPP_DIAGNOSTIC_POP
318299
# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
319300

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.

libcxx/include/__locale_dir/support/bsd_like.h

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

80-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
81-
return ::strtoll_l(__nptr, __endptr, __base, __loc);
82-
}
83-
84-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
85-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
86-
return ::strtoull_l(__nptr, __endptr, __base, __loc);
87-
}
88-
8980
//
9081
// Character manipulation functions
9182
//
@@ -219,12 +210,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __
219210
char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
220211
return ::asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...); // non-standard
221212
}
222-
223-
template <class... _Args>
224-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
225-
const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
226-
return ::sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
227-
}
228213
_LIBCPP_DIAGNOSTIC_POP
229214
#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
230215

libcxx/include/__locale_dir/support/fuchsia.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __
141141
__locale_guard __current(__loc);
142142
return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
143143
}
144-
template <class... _Args>
145-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
146-
const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
147-
__locale_guard __current(__loc);
148-
return std::sscanf(__s, __format, std::forward<_Args>(__args)...);
149-
}
150-
151144
_LIBCPP_DIAGNOSTIC_POP
152145
#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
153146

libcxx/include/__locale_dir/support/linux.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,6 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
9494
return ::strtold_l(__nptr, __endptr, __loc);
9595
}
9696

97-
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
98-
#if !_LIBCPP_HAS_MUSL_LIBC
99-
return ::strtoll_l(__nptr, __endptr, __base, __loc);
100-
#else
101-
(void)__loc;
102-
return ::strtoll(__nptr, __endptr, __base);
103-
#endif
104-
}
105-
106-
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
107-
__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
108-
#if !_LIBCPP_HAS_MUSL_LIBC
109-
return ::strtoull_l(__nptr, __endptr, __base, __loc);
110-
#else
111-
(void)__loc;
112-
return ::strtoull(__nptr, __endptr, __base);
113-
#endif
114-
}
115-
11697
//
11798
// Character manipulation functions
11899
//
@@ -267,20 +248,6 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
267248
va_end(__va);
268249
return __res;
269250
}
270-
271-
#ifndef _LIBCPP_COMPILER_GCC // GCC complains that this can't be always_inline due to C-style varargs
272-
_LIBCPP_HIDE_FROM_ABI
273-
#endif
274-
inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
275-
const char* __s, __locale_t __loc, const char* __format, ...) {
276-
va_list __va;
277-
va_start(__va, __format);
278-
__locale_guard __current(__loc);
279-
int __res = std::vsscanf(__s, __format, __va);
280-
va_end(__va);
281-
return __res;
282-
}
283-
284251
} // namespace __locale
285252
_LIBCPP_END_NAMESPACE_STD
286253

0 commit comments

Comments
 (0)