diff options
author | Alexander van Heukelum <heukelum@mailshack.com> | 2008-03-15 13:31:49 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-04-26 13:21:16 -0400 |
commit | 56a6b1eb7bfb5ace0b5cb9c149f502fbd101b8ab (patch) | |
tree | 46d3781050938b0649fc89cd8e7f612cacb66984 | |
parent | 7d9dff22e8ad06ad330968c9e3d3a2fb55a5f9c3 (diff) |
generic: implement __fls on all 64-bit archs
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>
-rw-r--r-- | include/asm-alpha/bitops.h | 5 | ||||
-rw-r--r-- | include/asm-ia64/bitops.h | 16 | ||||
-rw-r--r-- | include/asm-mips/bitops.h | 5 | ||||
-rw-r--r-- | include/asm-parisc/bitops.h | 1 | ||||
-rw-r--r-- | include/asm-powerpc/bitops.h | 5 | ||||
-rw-r--r-- | include/asm-s390/bitops.h | 1 | ||||
-rw-r--r-- | include/asm-sh/bitops.h | 1 | ||||
-rw-r--r-- | include/asm-sparc64/bitops.h | 1 |
8 files changed, 35 insertions, 0 deletions
diff --git a/include/asm-alpha/bitops.h b/include/asm-alpha/bitops.h index 9e19a704d484..15f3ae25c511 100644 --- a/include/asm-alpha/bitops.h +++ b/include/asm-alpha/bitops.h | |||
@@ -388,6 +388,11 @@ static inline int fls64(unsigned long x) | |||
388 | } | 388 | } |
389 | #endif | 389 | #endif |
390 | 390 | ||
391 | static inline unsigned long __fls(unsigned long x) | ||
392 | { | ||
393 | return fls64(x) - 1; | ||
394 | } | ||
395 | |||
391 | static inline int fls(int x) | 396 | static inline int fls(int x) |
392 | { | 397 | { |
393 | return fls64((unsigned int) x); | 398 | return fls64((unsigned int) x); |
diff --git a/include/asm-ia64/bitops.h b/include/asm-ia64/bitops.h index 953d3df9dd22..e2ca80037335 100644 --- a/include/asm-ia64/bitops.h +++ b/include/asm-ia64/bitops.h | |||
@@ -407,6 +407,22 @@ fls (int t) | |||
407 | return ia64_popcnt(x); | 407 | return ia64_popcnt(x); |
408 | } | 408 | } |
409 | 409 | ||
410 | /* | ||
411 | * Find the last (most significant) bit set. Undefined for x==0. | ||
412 | * Bits are numbered from 0..63 (e.g., __fls(9) == 3). | ||
413 | */ | ||
414 | static inline unsigned long | ||
415 | __fls (unsigned long x) | ||
416 | { | ||
417 | x |= x >> 1; | ||
418 | x |= x >> 2; | ||
419 | x |= x >> 4; | ||
420 | x |= x >> 8; | ||
421 | x |= x >> 16; | ||
422 | x |= x >> 32; | ||
423 | return ia64_popcnt(x) - 1; | ||
424 | } | ||
425 | |||
410 | #include <asm-generic/bitops/fls64.h> | 426 | #include <asm-generic/bitops/fls64.h> |
411 | 427 | ||
412 | /* | 428 | /* |
diff --git a/include/asm-mips/bitops.h b/include/asm-mips/bitops.h index ec75ce4cdb8c..c2bd126c3b4e 100644 --- a/include/asm-mips/bitops.h +++ b/include/asm-mips/bitops.h | |||
@@ -591,6 +591,11 @@ static inline int __ilog2(unsigned long x) | |||
591 | return 63 - lz; | 591 | return 63 - lz; |
592 | } | 592 | } |
593 | 593 | ||
594 | static inline unsigned long __fls(unsigned long x) | ||
595 | { | ||
596 | return __ilog2(x); | ||
597 | } | ||
598 | |||
594 | #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) | 599 | #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) |
595 | 600 | ||
596 | /* | 601 | /* |
diff --git a/include/asm-parisc/bitops.h b/include/asm-parisc/bitops.h index f8eebcbad01f..7a6ea10bd231 100644 --- a/include/asm-parisc/bitops.h +++ b/include/asm-parisc/bitops.h | |||
@@ -210,6 +210,7 @@ static __inline__ int fls(int x) | |||
210 | return ret; | 210 | return ret; |
211 | } | 211 | } |
212 | 212 | ||
213 | #include <asm-generic/bitops/__fls.h> | ||
213 | #include <asm-generic/bitops/fls64.h> | 214 | #include <asm-generic/bitops/fls64.h> |
214 | #include <asm-generic/bitops/hweight.h> | 215 | #include <asm-generic/bitops/hweight.h> |
215 | #include <asm-generic/bitops/lock.h> | 216 | #include <asm-generic/bitops/lock.h> |
diff --git a/include/asm-powerpc/bitops.h b/include/asm-powerpc/bitops.h index a99a74929475..897eade3afbe 100644 --- a/include/asm-powerpc/bitops.h +++ b/include/asm-powerpc/bitops.h | |||
@@ -313,6 +313,11 @@ static __inline__ int fls(unsigned int x) | |||
313 | return 32 - lz; | 313 | return 32 - lz; |
314 | } | 314 | } |
315 | 315 | ||
316 | static __inline__ unsigned long __fls(unsigned long x) | ||
317 | { | ||
318 | return __ilog2(x); | ||
319 | } | ||
320 | |||
316 | /* | 321 | /* |
317 | * 64-bit can do this using one cntlzd (count leading zeroes doubleword) | 322 | * 64-bit can do this using one cntlzd (count leading zeroes doubleword) |
318 | * instruction; for 32-bit we use the generic version, which does two | 323 | * instruction; for 32-bit we use the generic version, which does two |
diff --git a/include/asm-s390/bitops.h b/include/asm-s390/bitops.h index 965394e69452..b4eb24ab5af9 100644 --- a/include/asm-s390/bitops.h +++ b/include/asm-s390/bitops.h | |||
@@ -769,6 +769,7 @@ static inline int sched_find_first_bit(unsigned long *b) | |||
769 | } | 769 | } |
770 | 770 | ||
771 | #include <asm-generic/bitops/fls.h> | 771 | #include <asm-generic/bitops/fls.h> |
772 | #include <asm-generic/bitops/__fls.h> | ||
772 | #include <asm-generic/bitops/fls64.h> | 773 | #include <asm-generic/bitops/fls64.h> |
773 | 774 | ||
774 | #include <asm-generic/bitops/hweight.h> | 775 | #include <asm-generic/bitops/hweight.h> |
diff --git a/include/asm-sh/bitops.h b/include/asm-sh/bitops.h index b6ba5a60dec2..d7d382f63ee5 100644 --- a/include/asm-sh/bitops.h +++ b/include/asm-sh/bitops.h | |||
@@ -95,6 +95,7 @@ static inline unsigned long ffz(unsigned long word) | |||
95 | #include <asm-generic/bitops/ext2-atomic.h> | 95 | #include <asm-generic/bitops/ext2-atomic.h> |
96 | #include <asm-generic/bitops/minix.h> | 96 | #include <asm-generic/bitops/minix.h> |
97 | #include <asm-generic/bitops/fls.h> | 97 | #include <asm-generic/bitops/fls.h> |
98 | #include <asm-generic/bitops/__fls.h> | ||
98 | #include <asm-generic/bitops/fls64.h> | 99 | #include <asm-generic/bitops/fls64.h> |
99 | 100 | ||
100 | #endif /* __KERNEL__ */ | 101 | #endif /* __KERNEL__ */ |
diff --git a/include/asm-sparc64/bitops.h b/include/asm-sparc64/bitops.h index 982ce8992b91..11f9d8146cdf 100644 --- a/include/asm-sparc64/bitops.h +++ b/include/asm-sparc64/bitops.h | |||
@@ -34,6 +34,7 @@ extern void change_bit(unsigned long nr, volatile unsigned long *addr); | |||
34 | #include <asm-generic/bitops/ffz.h> | 34 | #include <asm-generic/bitops/ffz.h> |
35 | #include <asm-generic/bitops/__ffs.h> | 35 | #include <asm-generic/bitops/__ffs.h> |
36 | #include <asm-generic/bitops/fls.h> | 36 | #include <asm-generic/bitops/fls.h> |
37 | #include <asm-generic/bitops/__fls.h> | ||
37 | #include <asm-generic/bitops/fls64.h> | 38 | #include <asm-generic/bitops/fls64.h> |
38 | 39 | ||
39 | #ifdef __KERNEL__ | 40 | #ifdef __KERNEL__ |