From 7c8c2fc9a6d1008149ee8ce11a7958ab427fc05a Mon Sep 17 00:00:00 2001 Message-Id: <7c8c2fc9a6d1008149ee8ce11a7958ab427fc05a.1713953042.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 20 Apr 2008 15:59:58 +0100 Subject: [PATCH 1/1] Use fls() if available Organization: Straylight/Edgeware From: Richard Kettlewell --- configure.ac | 5 +++++ lib/bits.c | 3 ++- lib/bits.h | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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 */ -- [mdw]