[libc++][NFC] Remove MSVC specific code.

Switching `__builtin_clzll`  to `__libcpp_clz` should work on all
platforms and no longer require MSVC specific code.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D107709
This commit is contained in:
Mark de Wever 2021-08-08 11:02:07 +02:00
parent 3240000546
commit 96ed451f8d
1 changed files with 3 additions and 24 deletions

View File

@ -74,6 +74,7 @@ namespace std {
*/ */
#include <__availability> #include <__availability>
#include <__bits>
#include <__config> #include <__config>
#include <__errc> #include <__errc>
#include <__utility/to_underlying.h> #include <__utility/to_underlying.h>
@ -204,13 +205,11 @@ struct _LIBCPP_HIDDEN __traits_base
{ {
using type = uint64_t; using type = uint64_t;
#if !defined(_LIBCPP_COMPILER_MSVC)
static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v) static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
{ {
auto __t = (64 - __builtin_clzll(__v | 1)) * 1233 >> 12; auto __t = (64 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
return __t - (__v < __pow10_64[__t]) + 1; return __t - (__v < __pow10_64[__t]) + 1;
} }
#endif
_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_AVAILABILITY_TO_CHARS
static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p) static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
@ -227,13 +226,11 @@ struct _LIBCPP_HIDDEN
{ {
using type = uint32_t; using type = uint32_t;
#if !defined(_LIBCPP_COMPILER_MSVC)
static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v) static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
{ {
auto __t = (32 - __builtin_clz(__v | 1)) * 1233 >> 12; auto __t = (32 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
return __t - (__v < __pow10_32[__t]) + 1; return __t - (__v < __pow10_32[__t]) + 1;
} }
#endif
_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_AVAILABILITY_TO_CHARS
static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p) static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
@ -354,28 +351,10 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
using __tx = __itoa::__traits<_Tp>; using __tx = __itoa::__traits<_Tp>;
auto __diff = __last - __first; auto __diff = __last - __first;
#if !defined(_LIBCPP_COMPILER_MSVC)
if (__tx::digits <= __diff || __tx::__width(__value) <= __diff) if (__tx::digits <= __diff || __tx::__width(__value) <= __diff)
return {__tx::__convert(__value, __first), errc(0)}; return {__tx::__convert(__value, __first), errc(0)};
else else
return {__last, errc::value_too_large}; return {__last, errc::value_too_large};
#else
if (__tx::digits <= __diff)
return {__tx::__convert(__value, __first), {}};
else
{
char __buf[__tx::digits];
auto __p = __tx::__convert(__value, __buf);
auto __len = __p - __buf;
if (__len <= __diff)
{
_VSTD::memcpy(__first, __buf, __len);
return {__first + __len, {}};
}
else
return {__last, errc::value_too_large};
}
#endif
} }
template <typename _Tp> template <typename _Tp>