diff options
-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__ |