From: Christopher Dykes Date: Mon, 1 Aug 2016 22:26:51 +0000 (-0700) Subject: Fix the ffs builtins under MSVC X-Git-Tag: v2016.08.08.00~41 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fcd395244ded1a7adbb5df39ff00d4f9151b762f;p=folly.git 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 --- 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) {