Skip to content

Commit

Permalink
tile: fix bug where fls(0) was not returning 0
Browse files Browse the repository at this point in the history
This is because __builtin_clz(0) returns 64 for the "undefined" case
of 0, since the builtin just does a right-shift 32 and "clz" instruction.
So, use the alpha approach of casting to u32 and using __builtin_clzll().

Cc: stable@vger.kernel.org
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
  • Loading branch information
Chris Metcalf committed May 25, 2012
1 parent acd1a19 commit 9f1d62b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions arch/tile/include/asm/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ static inline int ffs(int x)
return __builtin_ffs(x);
}

static inline int fls64(__u64 w)
{
return (sizeof(__u64) * 8) - __builtin_clzll(w);
}

/**
* fls - find last set bit in word
* @x: the word to search
Expand All @@ -90,12 +95,7 @@ static inline int ffs(int x)
*/
static inline int fls(int x)
{
return (sizeof(int) * 8) - __builtin_clz(x);
}

static inline int fls64(__u64 w)
{
return (sizeof(__u64) * 8) - __builtin_clzll(w);
return fls64((unsigned int) x);
}

static inline unsigned int __arch_hweight32(unsigned int w)
Expand Down

0 comments on commit 9f1d62b

Please sign in to comment.