[libcxx-commits] [PATCH] D58021: Win32 does not have popcnt64 function and fix bug with defines in ctz function

Danila Kutenin via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 10 20:05:28 PST 2019


danlark created this revision.
danlark added a reviewer: mclow.lists.
Herald added a subscriber: ldionne.

Repository:
  rCXX libc++

https://reviews.llvm.org/D58021

Files:
  include/bit


Index: include/bit
===================================================================
--- include/bit
+++ include/bit
@@ -88,7 +88,7 @@
 inline _LIBCPP_INLINE_VISIBILITY
 int __ctz(unsigned long long __x) {
     unsigned long __where;
-#if defined(_LIBCPP_HAS_BITSCAN64)
+#if defined(_LIBCPP_HAS_BITSCAN64) && \
     (defined(_M_AMD64) || defined(__x86_64__))
   if (_BitScanForward64(&__where, __x))
     return static_cast<int>(__where);
@@ -147,7 +147,12 @@
 
 inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned long long __x) {
   static_assert(sizeof(unsigned long long) == 8, "");
+#if defined(_M_IX86)
+  // Win32 doesn't have __popcnt64 so emulate it with two 32 bit calls.
+  return __popcnt(__x) + __popcnt(__x >> 32);
+#else
   return __popcnt64(__x);
+#endif
 }
 
 #endif // _LIBCPP_COMPILER_MSVC


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58021.186177.patch
Type: text/x-patch
Size: 816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190211/00601c4e/attachment.bin>


More information about the libcxx-commits mailing list