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 9c8b406c1bc3e29bd495f0c5cab699e4e583203a..6dd8196d2e49231bf97bb4a651cd4b8571e886c8 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 4d7710520dc06574c64f74793551d85842cd4b8b..6256d056c324c7ec8df797251ad61a66fdd87d8f 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 4d7ea49dd1cdde71d004050875a95dc9c4c3ea80..a396c850345ddc8cb90042b34d7d39c723aea4c8 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 b49fd5f1344625f559a67a2071dfde226be11b01..972c623a0bfcd90c043ec776158606e10b93cf60 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 8d06c911abc33dee73331cefa3e7b0933464903b..f4eb855ebf340d8a002759c8384323cd63218a97 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 a6d1f1d04c593c72c3f4d6f01bbb78b10b525f0e..c662470a09142fa83c3ba337a84b7125ace2ed12 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