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(__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