X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fffs.cc;h=1ca913c54c3234710fda0cd0e9b396142c760c43;hb=5b40e073e9c973479c3d286a007c57e1e0fa3d0f;hp=8f7ecdb502413af98420c654496019f992458c4f;hpb=650964f3203319b013c49a286b5fc5fc203f3bbb;p=ardour.git diff --git a/libs/pbd/ffs.cc b/libs/pbd/ffs.cc index 8f7ecdb502..1ca913c54c 100644 --- a/libs/pbd/ffs.cc +++ b/libs/pbd/ffs.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Tim Mayberry + Copyright (C) 2013 Tim Mayberry This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,16 +19,30 @@ #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); + return ::ffs(x); #endif }