chiark / gitweb /
Use fls() if available
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 20 Apr 2008 14:59:58 +0000 (15:59 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 20 Apr 2008 14:59:58 +0000 (15:59 +0100)
configure.ac
lib/bits.c
lib/bits.h

index ece08f16f0981ff2d619584af3c3c611f2061910..e3e836487d2d638411bb2c23cc0c0e883b59eb24 100644 (file)
@@ -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
   # <db.h> had better be version 3 or later
   AC_CACHE_CHECK([db.h version],[rjk_cv_db_version],[
index d570e6407da875e2781b2c03dced9784634c7bec..6b5273b5d4fd6e5ef33304b6ea815f348825f40a 100644 (file)
@@ -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:
index 856db683c2a283036f0b70db4c21c11a1a97977d..0965cb602f044f664de5edbe3392b5951feeb106 100644 (file)
 #ifndef BITS_H
 #define BITS_H
 
+#include <string.h>                     /* 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 */