From: Jens Axboe Date: Wed, 9 Nov 2005 08:24:14 +0000 (+0100) Subject: [PATCH] Add generic_ffz for use for archs without an optimized version X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=2fa6471f93a50697668b232e7605e7350cfde86d;p=disktools.git [PATCH] Add generic_ffz for use for archs without an optimized version --- diff --git a/arch-alpha.h b/arch-alpha.h index b1b1e8a..09293bd 100644 --- a/arch-alpha.h +++ b/arch-alpha.h @@ -13,5 +13,6 @@ #endif #define nop do { } while (0) +#define ffz(v) generic_ffz((v)) #endif diff --git a/arch-s390.h b/arch-s390.h index 956dccf..b7048ad 100644 --- a/arch-s390.h +++ b/arch-s390.h @@ -13,5 +13,6 @@ #endif #define nop asm volatile ("diag 0,0,68" : : : "memory") +#define ffz(v) generic_ffz((v)) #endif diff --git a/arch.h b/arch.h index 44d09e9..4ea55bc 100644 --- a/arch.h +++ b/arch.h @@ -10,6 +10,17 @@ enum { arch_alpha, }; +static inline unsigned long generic_ffz(unsigned long word) +{ + int i; + + for (i = 0; i < sizeof(word) * 8; i++) + if ((word & (1UL << i)) == 0) + return i; + + return -1; +} + #if defined(__i386__) #include "arch-x86.h" #elif defined(__x86_64__)