Re: [mpm@selenic.com: Re: buggy ia64_fls() ? (was Re: /dev/random problem on 2.6.12-rc1)]

From: Matt Mackall <mpm_at_selenic.com>
Date: 2005-04-09 09:15:43
On Fri, Apr 08, 2005 at 04:01:11PM -0700, David Mosberger wrote:
> >>>>> On Fri, 8 Apr 2005 15:49:13 -0700, Matt Mackall <mpm@selenic.com> said:
> 
>   >> Yes, that'll give the right result for fls(-1).  But what'll it
>   >> give for fls(-2)?
> 
>   Matt> There's no such thing, it takes an unsigned long. There's two
>   Matt> problems:
> 
>   Matt> input generic_fls ia64_fls exponent (with bias +65535) 0000000
>   Matt> 0 -65535 0 0000001 1 0 65535 1000000 32 31 65566
> 
>   Matt> So there's the off-by-one problem. And then there's the huge
>   Matt> discontinuity at 0. Trouble is the bias is 65535 rather than
>   Matt> 65536 so there's no masking trick that works. We could instead
>   Matt> to do exp((x*2)+1).
> 
> ia64_fls() returns an undefined result for 0 and, as you observed,
> returns bit numbers starting from 0.  Also, ia64_fls() works on full
> 64-bit values, not just 32 bits.
> 
> Fixing fls() is trivial:
> 
> static inline int
> fls (int x)
> {
> 	if (!x)
> 		return 0;
> 	return ia64_fls((unsigned int) x) + 1;
> }

I was trying desperately to avoid the branch, as I understand there
are issues there on IA64. 

-- 
Mathematics is the supreme nostalgia of our time.
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Fri Apr 8 19:16:19 2005

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:37 EST