Implement __builtin_popcount under MSVC
authorChristopher Dykes <cdykes@fb.com>
Wed, 7 Jun 2017 23:03:27 +0000 (16:03 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 7 Jun 2017 23:12:08 +0000 (16:12 -0700)
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

index 817d1addd7e735da70c362bbd9e37022d4446f60..90179c8f453e2a85447176285516f6438c1f980d 100644 (file)
@@ -74,6 +74,10 @@ FOLLY_ALWAYS_INLINE int __builtin_ffsll(long long x) {
   return int(_BitScanForward64(&index, (unsigned long long)x) ? index + 1 : 0);
 }
 
   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));
 }
 FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
   return int(__popcnt64(x));
 }