Hi Vincent,

On Mon, Dec 08, 2014 at 11:45:13PM +0100, Vincent Bernat wrote:
>  ???  8 décembre 2014 23:20 +0100, Vincent Bernat <[email protected]> :
> 
> > Assuming that RAND_MAX is always a power of two - 1, 32 could be
> > replaced by a precomputed value of ffs(RAND_MAX+1)-1.
> 
> ebtree defines a fls64() function which seems best suited (RAND_MAX+1
> could overflow). Here is a proposed patch for this:

Good catch, but I'd rather simply divide by ((u64)RAND_MAX + 1) and
let gcc notice it's a power of two and implement a hard-coded constant
shift. There are a lot of things gcc doesn't figure well, but divides
and multiplies are generally performed optimally :-)

Thanks,
Willy


Reply via email to