On Tue, Dec 1, 2015 at 6:01 AM, barret rhoden <[email protected]> wrote:

> On 2015-11-30 at 19:43 'Davide Libenzi' via Akaros wrote:
> > Oh, I would not have made any comment, had I not seen the silly
> > optimization in place. Likely 1993 era 😀
> > No optimization in place, meant "we do not care at this point", which
> > I agree in this case.
> > But the code was suggesting "we do care", hence a much better way to
> > do it.
>
> I'm actually fine with just using:
>
> /* We wraparound if UINT_MAX < a * b, which is also UINT_MAX / a < b. */
> static inline bool mult_will_overflow_u64(uint64_t a, uint64_t b)
> {
>     if (!a)
>         return FALSE;
>     return (uint64_t)(-1) / a < b;
> }
>

That looks good to me, modulo maybe an unlikely(!a) 😀
We are dealing with an OS which does not have to deal with the past. And
the future has DIV becoming faster more than slower (today is about 20
cycles IIRC, on modern x86_64 CPUs).
The mulq (128bit) approach is likely faster (mulq faster than DIV, and no
branches), but we are splitting hairs here, in a place were there is no
need to, and both approaches are more readable than the current code.

-- 
You received this message because you are subscribed to the Google Groups 
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to