From: Jens Axboe Date: Sun, 1 Jun 2008 17:45:10 +0000 (+0200) Subject: Readd the arch ffz functions X-Git-Tag: fio-1.21-rc4~10 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=8f7e39dd35a40d088a31f33f12402a1eaf31b2c4 Readd the arch ffz functions 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 --- diff --git a/arch/arch-ia64.h b/arch/arch-ia64.h index 9c8b406c..6dd8196d 100644 --- a/arch/arch-ia64.h +++ b/arch/arch-ia64.h @@ -21,4 +21,17 @@ #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 diff --git a/arch/arch-ppc.h b/arch/arch-ppc.h index 4d771052..6256d056 100644 --- a/arch/arch-ppc.h +++ b/arch/arch-ppc.h @@ -28,4 +28,20 @@ __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 diff --git a/arch/arch-x86.h b/arch/arch-x86.h index 4d7ea49d..a396c850 100644 --- a/arch/arch-x86.h +++ b/arch/arch-x86.h @@ -32,4 +32,11 @@ #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 diff --git a/arch/arch-x86_64.h b/arch/arch-x86_64.h index b49fd5f1..972c623a 100644 --- a/arch/arch-x86_64.h +++ b/arch/arch-x86_64.h @@ -32,4 +32,11 @@ #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 diff --git a/arch/arch.h b/arch/arch.h index 8d06c911..f4eb855e 100644 --- a/arch/arch.h +++ b/arch/arch.h @@ -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 a6d1f1d0..c662470a 100644 --- 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