From 4929771e2f6251bfe22cf72b5bd08905625f6d64 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Wed, 7 Jun 2017 16:03:27 -0700 Subject: [PATCH] Implement __builtin_popcount under MSVC Summary: I thought I had already implemented this, but apparently I had only implemented the ll variable. Whoops. This implements the 32-bit version which fixes the build on Windows. Reviewed By: yfeldblum Differential Revision: D5203680 fbshipit-source-id: 02b133db59e232cac586944b0ffc0e8bbf5f533a --- folly/portability/Builtins.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/folly/portability/Builtins.h b/folly/portability/Builtins.h index 817d1add..90179c8f 100644 --- a/folly/portability/Builtins.h +++ b/folly/portability/Builtins.h @@ -74,6 +74,10 @@ FOLLY_ALWAYS_INLINE int __builtin_ffsll(long long x) { return int(_BitScanForward64(&index, (unsigned long long)x) ? index + 1 : 0); } +FOLLY_ALWAYS_INLINE int __builtin_popcount(unsigned int x) { + return int(__popcnt(x)); +} + FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) { return int(__popcnt64(x)); } -- 2.34.1