From 9d774969fcf8539aa301b20d659710407b7b4e83 Mon Sep 17 00:00:00 2001 From: John Emmas Date: Thu, 18 Jul 2013 12:08:34 +0100 Subject: Adapt libs/pbd/ffs.cc to be buildable with MSVC --- libs/pbd/ffs.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'libs') 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 +#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 -- cgit v1.2.3