]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
generic: implement __fls on all 64-bit archs
authorAlexander van Heukelum <heukelum@mailshack.com>
Sat, 15 Mar 2008 17:31:49 +0000 (18:31 +0100)
committerIngo Molnar <mingo@elte.hu>
Sat, 26 Apr 2008 17:21:16 +0000 (19:21 +0200)
Implement __fls on all 64-bit archs:

alpha has an implementation of fls64.
Added __fls(x) = fls64(x) - 1.

ia64 has fls, but not __fls.
Added __fls based on code of fls.

mips and powerpc have __ilog2, which is the same as __fls.
Added __fls = __ilog2.

parisc, s390, sh and sparc64:
Include generic __fls.

x86_64 already has __fls.

Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/asm-alpha/bitops.h
include/asm-ia64/bitops.h
include/asm-mips/bitops.h
include/asm-parisc/bitops.h
include/asm-powerpc/bitops.h
include/asm-s390/bitops.h
include/asm-sh/bitops.h
include/asm-sparc64/bitops.h

index 9e19a704d4840693a31bd88413060024e3623266..15f3ae25c51137bb8af4a67b5d5e8cbbea328241 100644 (file)
@@ -388,6 +388,11 @@ static inline int fls64(unsigned long x)
 }
 #endif
 
+static inline unsigned long __fls(unsigned long x)
+{
+       return fls64(x) - 1;
+}
+
 static inline int fls(int x)
 {
        return fls64((unsigned int) x);
index 953d3df9dd22670f16fec92440a9dc18f5431593..e2ca800373351d26b1042394275ebe10f6c8d23e 100644 (file)
@@ -407,6 +407,22 @@ fls (int t)
        return ia64_popcnt(x);
 }
 
+/*
+ * Find the last (most significant) bit set.  Undefined for x==0.
+ * Bits are numbered from 0..63 (e.g., __fls(9) == 3).
+ */
+static inline unsigned long
+__fls (unsigned long x)
+{
+       x |= x >> 1;
+       x |= x >> 2;
+       x |= x >> 4;
+       x |= x >> 8;
+       x |= x >> 16;
+       x |= x >> 32;
+       return ia64_popcnt(x) - 1;
+}
+
 #include <asm-generic/bitops/fls64.h>
 
 /*
index ec75ce4cdb8c3e90307e51350c2d7dc4b950a4d5..c2bd126c3b4eda2613c73e26335bb0f8694abd9d 100644 (file)
@@ -591,6 +591,11 @@ static inline int __ilog2(unsigned long x)
        return 63 - lz;
 }
 
+static inline unsigned long __fls(unsigned long x)
+{
+       return __ilog2(x);
+}
+
 #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
 
 /*
index f8eebcbad01f81d57e0a222d4573d9044f114e96..7a6ea10bd231a051217ddd00b0f9318a604b1878 100644 (file)
@@ -210,6 +210,7 @@ static __inline__ int fls(int x)
        return ret;
 }
 
+#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 #include <asm-generic/bitops/hweight.h>
 #include <asm-generic/bitops/lock.h>
index a99a749294753b3a77688a203998111ef01eff13..897eade3afbeb0109159de4e1eb855f42ddab4e0 100644 (file)
@@ -313,6 +313,11 @@ static __inline__ int fls(unsigned int x)
        return 32 - lz;
 }
 
+static __inline__ unsigned long __fls(unsigned long x)
+{
+       return __ilog2(x);
+}
+
 /*
  * 64-bit can do this using one cntlzd (count leading zeroes doubleword)
  * instruction; for 32-bit we use the generic version, which does two
index 965394e69452daf2cf856a5a54472cbb7f1ab8e4..b4eb24ab5af97811e5a0ca1845607de238210863 100644 (file)
@@ -769,6 +769,7 @@ static inline int sched_find_first_bit(unsigned long *b)
 }
 
 #include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 
 #include <asm-generic/bitops/hweight.h>
index b6ba5a60dec217b4b7f4421db7cc8e402c2e15d4..d7d382f63ee53a5c6a59a7033169ba6bc366cb8f 100644 (file)
@@ -95,6 +95,7 @@ static inline unsigned long ffz(unsigned long word)
 #include <asm-generic/bitops/ext2-atomic.h>
 #include <asm-generic/bitops/minix.h>
 #include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 
 #endif /* __KERNEL__ */
index 982ce8992b91fcae6a2d9e790235b718d7cfa1b1..11f9d8146cdff0823500641bacde73d97c33151f 100644 (file)
@@ -34,6 +34,7 @@ extern void change_bit(unsigned long nr, volatile unsigned long *addr);
 #include <asm-generic/bitops/ffz.h>
 #include <asm-generic/bitops/__ffs.h>
 #include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 
 #ifdef __KERNEL__