❦ 10 décembre 2014 06:00 +0100, Willy Tarreau <[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 :-)
:) I didn't think of that.
--
Don't just echo the code with comments - make every comment count.
- The Elements of Programming Style (Kernighan & Plauger)