Readd the arch ffz functions
authorJens Axboe <jens.axboe@oracle.com>
Sun, 1 Jun 2008 17:45:10 +0000 (19:45 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Sun, 1 Jun 2008 17:45:10 +0000 (19:45 +0200)
May as well use the single op version if we have them, it's
generally a lot faster than the generic_ffz()

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
arch/arch-ia64.h
arch/arch-ppc.h
arch/arch-x86.h
arch/arch-x86_64.h
arch/arch.h
io_u.c

index 9c8b406..6dd8196 100644 (file)
 #define nop            asm volatile ("hint @pause" ::: "memory");
 #define read_barrier() asm volatile ("mf" ::: "memory")
 
+#define ia64_popcnt(x)                                                 \
+({                                                                     \
+       unsigned long ia64_intri_res;                                   \
+       asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x));         \
+       ia64_intri_res;                                                 \
+})
+
+static inline unsigned long arch_ffz(unsigned long bitmask)
+{
+       return ia64_popcnt(bitmask & (~bitmask - 1));
+}
+#define ARCH_HAVE_FFZ
+
 #endif
index 4d77105..6256d05 100644 (file)
        __asm__ __volatile__ ("sync" : : : "memory")
 #endif
 
+static inline int __ilog2(unsigned long bitmask)
+{
+       int lz;
+
+       asm ("cntlzw %0,%1" : "=r" (lz) : "r" (bitmask));
+       return 31 - lz;
+}
+
+static inline int arch_ffz(unsigned long bitmask)
+{
+       if ((bitmask = ~bitmask) == 0)
+               return 32;
+       return  __ilog2(bitmask & -bitmask);
+}
+#define ARCH_HAVE_FFZ
+
 #endif
index 4d7ea49..a396c85 100644 (file)
 #define nop            __asm__ __volatile__("rep;nop": : :"memory")
 #define read_barrier() asm volatile ("": : :"memory")
 
+static inline unsigned long arch_ffz(unsigned long bitmask)
+{
+       __asm__("bsfl %1,%0" :"=r" (bitmask) :"r" (~bitmask));
+       return bitmask;
+}
+#define ARCH_HAVE_FFZ
+
 #endif
index b49fd5f..972c623 100644 (file)
 #define nop            __asm__ __volatile__("rep;nop": : :"memory")
 #define read_barrier() asm volatile("lfence":::"memory")
 
+static inline unsigned long arch_ffz(unsigned long bitmask)
+{
+       __asm__("bsfq %1,%0" :"=r" (bitmask) :"r" (~bitmask));
+       return bitmask;
+}
+#define ARCH_HAVE_FFZ
+
 #endif
index 8d06c91..f4eb855 100644 (file)
@@ -32,4 +32,10 @@ enum {
 #error "Unsupported arch"
 #endif
 
+#ifdef ARCH_HAVE_FFZ
+#define ffz(bitmask)   arch_ffz(bitmask)
+#else
+#include "../lib/ffz.h"
+#endif
+
 #endif
diff --git a/io_u.c b/io_u.c
index a6d1f1d..c662470 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -7,7 +7,6 @@
 
 #include "fio.h"
 #include "hash.h"
-#include "lib/ffz.h"
 
 /*
  * Change this define to play with the timeout handling