aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-mips/bitops.h
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@shinybook.infradead.org>2006-04-28 20:42:26 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2006-04-28 20:42:26 -0400
commitd6754b401a15eaa16492ea5dbaa4826361d3f411 (patch)
tree032f067d3af458527d903a7653885404ed82431e /include/asm-mips/bitops.h
parentacc429a517bd11fdcac9bea97d082d26231beb92 (diff)
parent693f7d362055261882659475d2ef022e32edbff1 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'include/asm-mips/bitops.h')
-rw-r--r--include/asm-mips/bitops.h56
1 files changed, 24 insertions, 32 deletions
diff --git a/include/asm-mips/bitops.h b/include/asm-mips/bitops.h
index 0e71df31f81c..098cec263681 100644
--- a/include/asm-mips/bitops.h
+++ b/include/asm-mips/bitops.h
@@ -466,64 +466,56 @@ static inline unsigned long __ffs(unsigned long word)
466} 466}
467 467
468/* 468/*
469 * ffs - find first bit set. 469 * fls - find last bit set.
470 * @word: The word to search 470 * @word: The word to search
471 * 471 *
472 * Returns 1..SZLONG 472 * This is defined the same way as ffs.
473 * Returns 0 if no bit exists 473 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
474 */ 474 */
475 475static inline int fls(int word)
476static inline unsigned long ffs(unsigned long word)
477{ 476{
478 if (!word) 477 __asm__ ("clz %0, %1" : "=r" (word) : "r" (word));
479 return 0;
480 478
481 return __ffs(word) + 1; 479 return 32 - word;
482} 480}
483 481
484/* 482#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPS64)
485 * ffz - find first zero in word. 483static inline int fls64(__u64 word)
486 * @word: The word to search
487 *
488 * Undefined if no zero exists, so code should check against ~0UL first.
489 */
490static inline unsigned long ffz(unsigned long word)
491{ 484{
492 return __ffs (~word); 485 __asm__ ("dclz %0, %1" : "=r" (word) : "r" (word));
486
487 return 64 - word;
493} 488}
489#else
490#include <asm-generic/bitops/fls64.h>
491#endif
494 492
495/* 493/*
496 * fls - find last bit set. 494 * ffs - find first bit set.
497 * @word: The word to search 495 * @word: The word to search
498 * 496 *
499 * Returns 1..SZLONG 497 * This is defined the same way as
500 * Returns 0 if no bit exists 498 * the libc and compiler builtin ffs routines, therefore
499 * differs in spirit from the above ffz (man ffs).
501 */ 500 */
502static inline unsigned long fls(unsigned long word) 501static inline int ffs(int word)
503{ 502{
504#ifdef CONFIG_CPU_MIPS32 503 if (!word)
505 __asm__ ("clz %0, %1" : "=r" (word) : "r" (word)); 504 return 0;
506
507 return 32 - word;
508#endif
509
510#ifdef CONFIG_CPU_MIPS64
511 __asm__ ("dclz %0, %1" : "=r" (word) : "r" (word));
512 505
513 return 64 - word; 506 return fls(word & -word);
514#endif
515} 507}
516 508
517#else 509#else
518 510
519#include <asm-generic/bitops/__ffs.h> 511#include <asm-generic/bitops/__ffs.h>
520#include <asm-generic/bitops/ffs.h> 512#include <asm-generic/bitops/ffs.h>
521#include <asm-generic/bitops/ffz.h>
522#include <asm-generic/bitops/fls.h> 513#include <asm-generic/bitops/fls.h>
514#include <asm-generic/bitops/fls64.h>
523 515
524#endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */ 516#endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */
525 517
526#include <asm-generic/bitops/fls64.h> 518#include <asm-generic/bitops/ffz.h>
527#include <asm-generic/bitops/find.h> 519#include <asm-generic/bitops/find.h>
528 520
529#ifdef __KERNEL__ 521#ifdef __KERNEL__