From: Richard Kettlewell Date: Sun, 20 Apr 2008 14:59:58 +0000 (+0100) Subject: Use fls() if available X-Git-Tag: 4.0~115^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/7c8c2fc9a6d1008149ee8ce11a7958ab427fc05a Use fls() if available --- diff --git a/configure.ac b/configure.ac index ece08f1..e3e8364 100644 --- a/configure.ac +++ b/configure.ac @@ -1,3 +1,4 @@ + # Process this file with autoconf to produce a configure script. # # This file is part of DisOrder. @@ -427,6 +428,10 @@ AC_CHECK_FUNCS([fdatasync],[:],[ if test ! -z "$missing_functions"; then AC_MSG_ERROR([missing functions:$missing_functions]) fi + +# Functions we can take or leave +AC_CHECK_FUNCS([fls]) + if test $want_server = yes; then # had better be version 3 or later AC_CACHE_CHECK([db.h version],[rjk_cv_db_version],[ diff --git a/lib/bits.c b/lib/bits.c index d570e64..6b5273b 100644 --- a/lib/bits.c +++ b/lib/bits.c @@ -29,6 +29,7 @@ #include "bits.h" +#if !HAVE_FLS /** @brief Compute index of leftmost 1 bit * @param n Integer * @return Index of leftmost 1 bit or -1 @@ -69,7 +70,7 @@ int leftmost_bit(uint32_t n) { */ return x - 1; } - +#endif /* Local Variables: diff --git a/lib/bits.h b/lib/bits.h index 856db68..0965cb6 100644 --- a/lib/bits.h +++ b/lib/bits.h @@ -25,7 +25,15 @@ #ifndef BITS_H #define BITS_H +#include /* for fls() */ + +#if HAVE_FLS +static inline int leftmost_bit(uint32_t n) { + return fls(n) - 1; +} +#else int leftmost_bit(uint32_t n); +#endif #endif /* BITS_H */