diff options
author | John Emmas <johne53@tiscali.co.uk> | 2013-07-18 12:08:34 +0100 |
---|---|---|
committer | John Emmas <johne53@tiscali.co.uk> | 2013-07-18 12:08:34 +0100 |
commit | 9d774969fcf8539aa301b20d659710407b7b4e83 (patch) | |
tree | 0f062cfc288ec874760845e38b5f57999c2e6622 | |
parent | 57e53d577b914ca1a56d2a59a9dd48a450c573ce (diff) |
Adapt libs/pbd/ffs.cc to be buildable with MSVC
-rw-r--r-- | libs/pbd/ffs.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libs/pbd/ffs.cc b/libs/pbd/ffs.cc index 0a61969e8a..557504f14e 100644 --- a/libs/pbd/ffs.cc +++ b/libs/pbd/ffs.cc @@ -19,14 +19,28 @@ #include "pbd/ffs.h" +#ifndef COMPILER_MSVC #include <strings.h> +#endif namespace PBD { int ffs (int x) { -#if defined(WIN32) && defined(__GNUC__) +#if defined (COMPILER_MINGW) return __builtin_ffs(x); +#elif defined (COMPILER_MSVC) + unsigned long index; +#ifdef WIN64 + if (0 != _BitScanForward64(&index, (__int64)x)) +#else + if (0 != _BitScanForward(&index, (unsigned long)x)) +#endif + index++; // Make the result 1-based + else + index = 0; // All bits were zero + + return (int)index; #else return ::ffs(x); #endif |