diff options
author | Atsushi Nemoto <anemo@mba.ocn.ne.jp> | 2006-04-17 08:19:12 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2006-04-27 10:13:49 -0400 |
commit | bc818247203a7bfc40296a3f5b760de84fb8e0d1 (patch) | |
tree | e0e6248b181f0e5e89349a083e60fc3812b1bf94 /include/asm-mips | |
parent | c0858d82faf96ffc32b96e23927d10844d38e564 (diff) |
[MIPS] Fix bitops for MIPS32/MIPS64 CPUs.
With recent rewrite for generic bitops, fls() for 32bit kernel with
MIPS64_CPU is broken. Also, ffs(), fls() should be defined the same
way as the libc and compiler built-in routines (returns int instead of
unsigned long).
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'include/asm-mips')
-rw-r--r-- | include/asm-mips/bitops.h | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/include/asm-mips/bitops.h b/include/asm-mips/bitops.h index a1728f8c0705..d2f444537e4b 100644 --- a/include/asm-mips/bitops.h +++ b/include/asm-mips/bitops.h | |||
@@ -467,64 +467,56 @@ static inline unsigned long __ffs(unsigned long word) | |||
467 | } | 467 | } |
468 | 468 | ||
469 | /* | 469 | /* |
470 | * ffs - find first bit set. | 470 | * fls - find last bit set. |
471 | * @word: The word to search | 471 | * @word: The word to search |
472 | * | 472 | * |
473 | * Returns 1..SZLONG | 473 | * This is defined the same way as ffs. |
474 | * Returns 0 if no bit exists | 474 | * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. |
475 | */ | 475 | */ |
476 | 476 | static inline int fls(int word) | |
477 | static inline unsigned long ffs(unsigned long word) | ||
478 | { | 477 | { |
479 | if (!word) | 478 | __asm__ ("clz %0, %1" : "=r" (word) : "r" (word)); |
480 | return 0; | ||
481 | 479 | ||
482 | return __ffs(word) + 1; | 480 | return 32 - word; |
483 | } | 481 | } |
484 | 482 | ||
485 | /* | 483 | #if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPS64) |
486 | * ffz - find first zero in word. | 484 | static inline int fls64(__u64 word) |
487 | * @word: The word to search | ||
488 | * | ||
489 | * Undefined if no zero exists, so code should check against ~0UL first. | ||
490 | */ | ||
491 | static inline unsigned long ffz(unsigned long word) | ||
492 | { | 485 | { |
493 | return __ffs (~word); | 486 | __asm__ ("dclz %0, %1" : "=r" (word) : "r" (word)); |
487 | |||
488 | return 64 - word; | ||
494 | } | 489 | } |
490 | #else | ||
491 | #include <asm-generic/bitops/fls64.h> | ||
492 | #endif | ||
495 | 493 | ||
496 | /* | 494 | /* |
497 | * fls - find last bit set. | 495 | * ffs - find first bit set. |
498 | * @word: The word to search | 496 | * @word: The word to search |
499 | * | 497 | * |
500 | * Returns 1..SZLONG | 498 | * This is defined the same way as |
501 | * Returns 0 if no bit exists | 499 | * the libc and compiler builtin ffs routines, therefore |
500 | * differs in spirit from the above ffz (man ffs). | ||
502 | */ | 501 | */ |
503 | static inline unsigned long fls(unsigned long word) | 502 | static inline int ffs(int word) |
504 | { | 503 | { |
505 | #ifdef CONFIG_CPU_MIPS32 | 504 | if (!word) |
506 | __asm__ ("clz %0, %1" : "=r" (word) : "r" (word)); | 505 | return 0; |
507 | |||
508 | return 32 - word; | ||
509 | #endif | ||
510 | |||
511 | #ifdef CONFIG_CPU_MIPS64 | ||
512 | __asm__ ("dclz %0, %1" : "=r" (word) : "r" (word)); | ||
513 | 506 | ||
514 | return 64 - word; | 507 | return fls(word & -word); |
515 | #endif | ||
516 | } | 508 | } |
517 | 509 | ||
518 | #else | 510 | #else |
519 | 511 | ||
520 | #include <asm-generic/bitops/__ffs.h> | 512 | #include <asm-generic/bitops/__ffs.h> |
521 | #include <asm-generic/bitops/ffs.h> | 513 | #include <asm-generic/bitops/ffs.h> |
522 | #include <asm-generic/bitops/ffz.h> | ||
523 | #include <asm-generic/bitops/fls.h> | 514 | #include <asm-generic/bitops/fls.h> |
515 | #include <asm-generic/bitops/fls64.h> | ||
524 | 516 | ||
525 | #endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */ | 517 | #endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */ |
526 | 518 | ||
527 | #include <asm-generic/bitops/fls64.h> | 519 | #include <asm-generic/bitops/ffz.h> |
528 | #include <asm-generic/bitops/find.h> | 520 | #include <asm-generic/bitops/find.h> |
529 | 521 | ||
530 | #ifdef __KERNEL__ | 522 | #ifdef __KERNEL__ |