Implement __builtin_ctzll for MSVC
authorChristopher Dykes <cdykes@fb.com>
Wed, 4 May 2016 17:28:49 +0000 (10:28 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Wed, 4 May 2016 17:35:42 +0000 (10:35 -0700)
Summary: MSVC doesn't have it, but Folly uses it, so implement it in the Builtins portability header.

Reviewed By: yfeldblum

Differential Revision: D3256123

fb-gh-sync-id: fd9ea1b6098d97cf1fde4732905bae9bde8cd8ad
fbshipit-source-id: fd9ea1b6098d97cf1fde4732905bae9bde8cd8ad

folly/portability/Builtins.h

index 959ce5c283dd4cd2978be4a1b03cfba107e84c85..567ca6e90c46788964975a3cda867c970b0c9d32 100755 (executable)
@@ -35,6 +35,11 @@ FOLLY_ALWAYS_INLINE int __builtin_clzll(unsigned long long x) {
   return (int)(_BitScanReverse64(&index, x) ? 63 - index : 64);
 }
 
+FOLLY_ALWAYS_INLINE int __builtin_ctzll(unsigned long long x) {
+  unsigned long index;
+  return (int)(_BitScanForward64(&index, x) ? index : 64);
+}
+
 FOLLY_ALWAYS_INLINE int __builtin_ffs(int x) {
   unsigned long index;
   return (int)(_BitScanForward(&index, (unsigned long)x) ? index : 0);