On Wed, Dec 10, 2014 at 10:33:59AM +0100, Vincent Bernat wrote:
>  ??? 10 décembre 2014 06:00 +0100, Willy Tarreau <w...@1wt.eu> :
> 
> >> > 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 :-)
> 
> So, here is an updated patch:

Thank you Vincent, I've now applied it to both 1.5 and 1.6.

Cheers,
Willy


Reply via email to