aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-mips/bitops.h
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2005-10-07 11:58:15 -0400
committerRalf Baechle <ralf@linux-mips.org>2005-10-29 14:32:37 -0400
commitec917c2c1ab4359a1d438e62daeb50cc42e632e1 (patch)
treedeb2e00bee354577e1f19b7b70c1a2037828a957 /include/asm-mips/bitops.h
parentf92c1759a40a85f52b835c21b0ef6ce556b340c5 (diff)
Fixup a few lose ends in explicit support for MIPS R1/R2.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'include/asm-mips/bitops.h')
-rw-r--r--include/asm-mips/bitops.h54
1 files changed, 27 insertions, 27 deletions
diff --git a/include/asm-mips/bitops.h b/include/asm-mips/bitops.h
index 2ba20730a3e..5496f9064a6 100644
--- a/include/asm-mips/bitops.h
+++ b/include/asm-mips/bitops.h
@@ -12,6 +12,7 @@
12#include <linux/config.h> 12#include <linux/config.h>
13#include <linux/compiler.h> 13#include <linux/compiler.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <asm/bug.h>
15#include <asm/byteorder.h> /* sigh ... */ 16#include <asm/byteorder.h> /* sigh ... */
16#include <asm/cpu-features.h> 17#include <asm/cpu-features.h>
17 18
@@ -546,33 +547,27 @@ static inline int test_bit(unsigned long nr, const volatile unsigned long *addr)
546 return 1UL & (addr[nr >> SZLONG_LOG] >> (nr & SZLONG_MASK)); 547 return 1UL & (addr[nr >> SZLONG_LOG] >> (nr & SZLONG_MASK));
547} 548}
548 549
549#ifdef CONFIG_CPU_MIPS32_R1
550/* 550/*
551 * Return the bit position (0..31) of the most significant 1 bit in a word 551 * Return the bit position (0..63) of the most significant 1 bit in a word
552 * Returns -1 if no 1 bit exists 552 * Returns -1 if no 1 bit exists
553 */ 553 */
554static __inline__ int __ilog2(unsigned long x) 554static inline int __ilog2(unsigned long x)
555{ 555{
556 int lz; 556 int lz;
557 557
558 __asm__ ( 558 if (sizeof(x) == 4) {
559 " .set push \n" 559 __asm__ (
560 " .set mips32 \n" 560 " .set push \n"
561 " clz %0, %1 \n" 561 " .set mips32 \n"
562 " .set pop \n" 562 " clz %0, %1 \n"
563 : "=r" (lz) 563 " .set pop \n"
564 : "r" (x)); 564 : "=r" (lz)
565 : "r" (x));
565 566
566 return 31 - lz; 567 return 31 - lz;
567} 568 }
568#elif defined(CONFIG_CPU_MIPS64_R1) 569
569/* 570 BUG_ON(sizeof(x) != 8);
570 * Return the bit position (0..63) of the most significant 1 bit in a word
571 * Returns -1 if no 1 bit exists
572 */
573static __inline__ int __ilog2(unsigned long x)
574{
575 int lz;
576 571
577 __asm__ ( 572 __asm__ (
578 " .set push \n" 573 " .set push \n"
@@ -584,7 +579,6 @@ static __inline__ int __ilog2(unsigned long x)
584 579
585 return 63 - lz; 580 return 63 - lz;
586} 581}
587#endif
588 582
589/* 583/*
590 * __ffs - find first bit in word. 584 * __ffs - find first bit in word.
@@ -595,7 +589,7 @@ static __inline__ int __ilog2(unsigned long x)
595 */ 589 */
596static inline unsigned long __ffs(unsigned long word) 590static inline unsigned long __ffs(unsigned long word)
597{ 591{
598#if defined(CONFIG_CPU_MIPS32_R1) || defined(CONFIG_CPU_MIPS64_R1) 592#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
599 return __ilog2(word & -word); 593 return __ilog2(word & -word);
600#else 594#else
601 int b = 0, s; 595 int b = 0, s;
@@ -606,6 +600,8 @@ static inline unsigned long __ffs(unsigned long word)
606 s = 4; if (word << 28 != 0) s = 0; b += s; word >>= s; 600 s = 4; if (word << 28 != 0) s = 0; b += s; word >>= s;
607 s = 2; if (word << 30 != 0) s = 0; b += s; word >>= s; 601 s = 2; if (word << 30 != 0) s = 0; b += s; word >>= s;
608 s = 1; if (word << 31 != 0) s = 0; b += s; 602 s = 1; if (word << 31 != 0) s = 0; b += s;
603
604 return b;
609#endif 605#endif
610#ifdef CONFIG_64BIT 606#ifdef CONFIG_64BIT
611 s = 32; if (word << 32 != 0) s = 0; b += s; word >>= s; 607 s = 32; if (word << 32 != 0) s = 0; b += s; word >>= s;
@@ -614,9 +610,10 @@ static inline unsigned long __ffs(unsigned long word)
614 s = 4; if (word << 60 != 0) s = 0; b += s; word >>= s; 610 s = 4; if (word << 60 != 0) s = 0; b += s; word >>= s;
615 s = 2; if (word << 62 != 0) s = 0; b += s; word >>= s; 611 s = 2; if (word << 62 != 0) s = 0; b += s; word >>= s;
616 s = 1; if (word << 63 != 0) s = 0; b += s; 612 s = 1; if (word << 63 != 0) s = 0; b += s;
617#endif 613
618 return b; 614 return b;
619#endif 615#endif
616#endif
620} 617}
621 618
622/* 619/*
@@ -655,10 +652,10 @@ static inline unsigned long ffz(unsigned long word)
655 */ 652 */
656static inline unsigned long flz(unsigned long word) 653static inline unsigned long flz(unsigned long word)
657{ 654{
658#if defined(CONFIG_CPU_MIPS32_R1) || defined(CONFIG_CPU_MIPS64_R1) 655#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
659 return __ilog2(~word); 656 return __ilog2(~word);
660#else 657#else
661#if defined(CONFIG_32BIT) 658#ifdef CONFIG_32BIT
662 int r = 31, s; 659 int r = 31, s;
663 word = ~word; 660 word = ~word;
664 s = 16; if ((word & 0xffff0000)) s = 0; r -= s; word <<= s; 661 s = 16; if ((word & 0xffff0000)) s = 0; r -= s; word <<= s;
@@ -666,8 +663,10 @@ static inline unsigned long flz(unsigned long word)
666 s = 4; if ((word & 0xf0000000)) s = 0; r -= s; word <<= s; 663 s = 4; if ((word & 0xf0000000)) s = 0; r -= s; word <<= s;
667 s = 2; if ((word & 0xc0000000)) s = 0; r -= s; word <<= s; 664 s = 2; if ((word & 0xc0000000)) s = 0; r -= s; word <<= s;
668 s = 1; if ((word & 0x80000000)) s = 0; r -= s; 665 s = 1; if ((word & 0x80000000)) s = 0; r -= s;
666
667 return r;
669#endif 668#endif
670#if defined(CONFIG_64BIT) 669#ifdef CONFIG_64BIT
671 int r = 63, s; 670 int r = 63, s;
672 word = ~word; 671 word = ~word;
673 s = 32; if ((word & 0xffffffff00000000UL)) s = 0; r -= s; word <<= s; 672 s = 32; if ((word & 0xffffffff00000000UL)) s = 0; r -= s; word <<= s;
@@ -676,9 +675,10 @@ static inline unsigned long flz(unsigned long word)
676 s = 4; if ((word & 0xf000000000000000UL)) s = 0; r -= s; word <<= s; 675 s = 4; if ((word & 0xf000000000000000UL)) s = 0; r -= s; word <<= s;
677 s = 2; if ((word & 0xc000000000000000UL)) s = 0; r -= s; word <<= s; 676 s = 2; if ((word & 0xc000000000000000UL)) s = 0; r -= s; word <<= s;
678 s = 1; if ((word & 0x8000000000000000UL)) s = 0; r -= s; 677 s = 1; if ((word & 0x8000000000000000UL)) s = 0; r -= s;
679#endif 678
680 return r; 679 return r;
681#endif 680#endif
681#endif
682} 682}
683 683
684/* 684/*