Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 19908
b: refs/heads/master
c: 2caf190
h: refs/heads/master
v: v3
  • Loading branch information
Ralf Baechle committed Feb 7, 2006
1 parent fc46773 commit 73bbab8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2e66fe24d6faa287088ff18051dd423a32b60502
refs/heads/master: 2caf190002770b53fdb263ed744802a1b5e81649
58 changes: 32 additions & 26 deletions trunk/include/asm-mips/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,31 +644,50 @@ static inline unsigned long ffz(unsigned long word)
}

/*
* flz - find last zero in word.
* fls - find last bit set.
* @word: The word to search
*
* Returns 0..SZLONG-1
* Undefined if no zero exists, so code should check against ~0UL first.
* Returns 1..SZLONG
* Returns 0 if no bit exists
*/
static inline unsigned long flz(unsigned long word)
static inline unsigned long fls(unsigned long word)
{
#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
return __ilog2(~word);
#else
#ifdef CONFIG_32BIT
int r = 31, s;
word = ~word;
#ifdef CONFIG_CPU_MIPS32
__asm__ ("clz %0, %1" : "=r" (word) : "r" (word));

return 32 - word;
#else
{
int r = 32, s;

if (word == 0)
return 0;

s = 16; if ((word & 0xffff0000)) s = 0; r -= s; word <<= s;
s = 8; if ((word & 0xff000000)) s = 0; r -= s; word <<= s;
s = 4; if ((word & 0xf0000000)) s = 0; r -= s; word <<= s;
s = 2; if ((word & 0xc0000000)) s = 0; r -= s; word <<= s;
s = 1; if ((word & 0x80000000)) s = 0; r -= s;

return r;
}
#endif
#endif /* CONFIG_32BIT */

#ifdef CONFIG_64BIT
int r = 63, s;
word = ~word;
#ifdef CONFIG_CPU_MIPS64

__asm__ ("dclz %0, %1" : "=r" (word) : "r" (word));

return 64 - word;
#else
{
int r = 64, s;

if (word == 0)
return 0;

s = 32; if ((word & 0xffffffff00000000UL)) s = 0; r -= s; word <<= s;
s = 16; if ((word & 0xffff000000000000UL)) s = 0; r -= s; word <<= s;
s = 8; if ((word & 0xff00000000000000UL)) s = 0; r -= s; word <<= s;
Expand All @@ -677,24 +696,11 @@ static inline unsigned long flz(unsigned long word)
s = 1; if ((word & 0x8000000000000000UL)) s = 0; r -= s;

return r;
}
#endif
#endif
#endif /* CONFIG_64BIT */
}

/*
* fls - find last bit set.
* @word: The word to search
*
* Returns 1..SZLONG
* Returns 0 if no bit exists
*/
static inline unsigned long fls(unsigned long word)
{
if (word == 0)
return 0;

return flz(~word) + 1;
}
#define fls64(x) generic_fls64(x)

/*
Expand Down

0 comments on commit 73bbab8

Please sign in to comment.