>From 353cc7c6906f650fa228d295dad270637f9441c7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 4 Aug 2020 00:05:05 +0200 Subject: [PATCH 1/6] ffs: Optimize for MSVC. * lib/ffs.c: Include . (ffs): With MSVC, use the _BitScanForward built-in. --- ChangeLog | 6 ++++++ lib/ffs.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index 526747e..773a9f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-08-03 Bruno Haible + ffs: Optimize for MSVC. + * lib/ffs.c: Include . + (ffs): With MSVC, use the _BitScanForward built-in. + +2020-08-03 Bruno Haible + sigprocmask: Try to avoid breakage for people who use an Autoconf cache. * m4/signalblocking.m4 (gl_SIGNALBLOCKING): Change the name of the cache variable. diff --git a/lib/ffs.c b/lib/ffs.c index ba4915e..d8a65ca 100644 --- a/lib/ffs.c +++ b/lib/ffs.c @@ -23,11 +23,23 @@ #include +#if defined _MSC_VER +# include +#endif + int ffs (int i) { #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) return __builtin_ffs (i); +#elif defined _MSC_VER + /* _BitScanForward + */ + unsigned long bit; + if (_BitScanForward (&bit, i)) + return bit + 1; + else + return 0; #else /* gives this deBruijn constant for a branch-less computation, although -- 2.7.4