* lib/ffs.c: Include <intrin.h>.
(ffs): With MSVC, use the _BitScanForward built-in.
+2020-08-03 Bruno Haible <bruno@clisp.org>
+
+ ffs: Optimize for MSVC.
+ * lib/ffs.c: Include <intrin.h>.
+ (ffs): With MSVC, use the _BitScanForward built-in.
+
2020-08-03 Bruno Haible <bruno@clisp.org>
sigprocmask: Try to avoid breakage for people who use an Autoconf cache.
#include <limits.h>
+#if defined _MSC_VER
+# include <intrin.h>
+#endif
+
int
ffs (int i)
{
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
return __builtin_ffs (i);
+#elif defined _MSC_VER
+ /* _BitScanForward
+ <https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64> */
+ unsigned long bit;
+ if (_BitScanForward (&bit, i))
+ return bit + 1;
+ else
+ return 0;
#else
/* <https://github.com/gibsjose/BitHacks>
gives this deBruijn constant for a branch-less computation, although