[libcxx-commits] [PATCH] D107709: [libc++][NFC] Remove MSVC specific code.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 8 02:04:18 PDT 2021


Mordante created this revision.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107709

Files:
  libcxx/include/charconv


Index: libcxx/include/charconv
===================================================================
--- libcxx/include/charconv
+++ libcxx/include/charconv
@@ -74,6 +74,7 @@
 */
 
 #include <__availability>
+#include <__bits>
 #include <__config>
 #include <__errc>
 #include <__utility/to_underlying.h>
@@ -204,13 +205,11 @@
 {
     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 @@
 {
     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 @@
     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>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107709.365007.patch
Type: text/x-patch
Size: 2105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210808/07c620f2/attachment.bin>


More information about the libcxx-commits mailing list