From fcd395244ded1a7adbb5df39ff00d4f9151b762f Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Mon, 1 Aug 2016 15:26:51 -0700 Subject: [PATCH] Fix the ffs builtins under MSVC Summary: I was off by one in my implementation. Reviewed By: yfeldblum Differential Revision: D3651183 fbshipit-source-id: 4d6a6d08c06bce332a00088920bf604a10c942e7 --- folly/portability/Builtins.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/portability/Builtins.h b/folly/portability/Builtins.h index 567ca6e9..755e0299 100755 --- a/folly/portability/Builtins.h +++ b/folly/portability/Builtins.h @@ -42,14 +42,14 @@ FOLLY_ALWAYS_INLINE int __builtin_ctzll(unsigned long long x) { FOLLY_ALWAYS_INLINE int __builtin_ffs(int x) { unsigned long index; - return (int)(_BitScanForward(&index, (unsigned long)x) ? index : 0); + return (int)(_BitScanForward(&index, (unsigned long)x) ? index + 1 : 0); } FOLLY_ALWAYS_INLINE int __builtin_ffsl(long x) { return __builtin_ffs((int)x); } FOLLY_ALWAYS_INLINE int __builtin_ffsll(long long x) { unsigned long index; - return (int)(_BitScanForward64(&index, (unsigned long long)x) ? index : 0); + return (int)(_BitScanForward64(&index, (unsigned long long)x) ? index + 1 : 0); } FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) { -- 2.34.1