From 98ded536df975fa3fea9290d38640ce2238db29f Mon Sep 17 00:00:00 2001 From: yury Date: Fri, 19 Sep 2008 18:46:04 +0000 Subject: [PATCH] b=16776 r=shadow - fls for class_hash.c --- lnet/include/libcfs/user-bitops.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lnet/include/libcfs/user-bitops.h b/lnet/include/libcfs/user-bitops.h index 0c8aae9..3147f72 100644 --- a/lnet/include/libcfs/user-bitops.h +++ b/lnet/include/libcfs/user-bitops.h @@ -74,6 +74,41 @@ static __inline__ int test_bit(int nr, const unsigned long *addr) } /* using binary seach */ +static __inline__ unsigned long __fls(long data) +{ + int pos = 32; + + if (!data) + return 0; + +#if BITS_PER_LONG == 64 + if ((data & 0xFFFFFFFF) == 0) + data <<= 32; +#endif + + if (!(data & 0xFFFF0000u)) { + data <<= 16; + pos -= 16; + } + if (!(data & 0xFF000000u)) { + data <<= 8; + pos -= 8; + } + if (!(data & 0xF0000000u)) { + data <<= 4; + pos -= 4; + } + if (!(data & 0xC0000000u)) { + data <<= 2; + pos -= 2; + } + if (!(data & 0x80000000u)) { + data <<= 1; + pos -= 1; + } + return pos; +} + static __inline__ unsigned long __ffs(long data) { int pos = 0; @@ -107,6 +142,7 @@ static __inline__ unsigned long __ffs(long data) } #define __ffz(x) __ffs(~(x)) +#define __flz(x) __fls(~(x)) unsigned long find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset); -- 1.8.3.1