[libcxx-commits] [libcxx] 96ed451 - [libc++][NFC] Remove MSVC specific code.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 9 09:13:56 PDT 2021


Author: Mark de Wever
Date: 2021-08-09T18:13:49+02:00
New Revision: 96ed451f8d5df711c6dd4887909cba8493454951

URL: https://github.com/llvm/llvm-project/commit/96ed451f8d5df711c6dd4887909cba8493454951
DIFF: https://github.com/llvm/llvm-project/commit/96ed451f8d5df711c6dd4887909cba8493454951.diff

LOG: [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

Added: 
    

Modified: 
    libcxx/include/charconv

Removed: 
    


################################################################################
diff  --git a/libcxx/include/charconv b/libcxx/include/charconv
index de34112d8eb37..b4ac71064fd1e 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -74,6 +74,7 @@ namespace std {
 */
 
 #include <__availability>
+#include <__bits>
 #include <__config>
 #include <__errc>
 #include <__utility/to_underlying.h>
@@ -204,13 +205,11 @@ struct _LIBCPP_HIDDEN __traits_base
 {
     using type = uint64_t;
 
-#if !defined(_LIBCPP_COMPILER_MSVC)
     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;
     }
-#endif
 
     _LIBCPP_AVAILABILITY_TO_CHARS
     static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
@@ -227,13 +226,11 @@ struct _LIBCPP_HIDDEN
 {
     using type = uint32_t;
 
-#if !defined(_LIBCPP_COMPILER_MSVC)
     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;
     }
-#endif
 
     _LIBCPP_AVAILABILITY_TO_CHARS
     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>;
     auto __
diff  = __last - __first;
 
-#if !defined(_LIBCPP_COMPILER_MSVC)
     if (__tx::digits <= __
diff  || __tx::__width(__value) <= __
diff )
         return {__tx::__convert(__value, __first), errc(0)};
     else
         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>


        


More information about the libcxx-commits mailing list