Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 23 Jun 2024 14:33:20 -0400
From: Rich Felker <dalias@...c.org>
To: Damian McGuckin <damianm@....com.au>
Cc: MUSL <musl@...ts.openwall.com>
Subject: Re: roundf() (and round(), and ...)

On Fri, Jun 21, 2024 at 06:12:22PM +1000, Damian McGuckin wrote:
> 
> There is an optimization in roundf() (and an equivalent in round())
> which handles the case of numbers 0 < |x| < 0.5
> 
>     if (e < 0x7f-1) {
>         return 0*u.f;
>     }
> 
> If one has lots of numbers close to zero (as you would if you were
> testing even possible 32-bit floating point number or for any other
> reason), this
> can mean a total run time is 5% faster overall (at the expense of
> the performance of cases for |x| >= 0.5.
> 
> Is such an optimization worth it? And yes, we re not talking about lots of
> compute cycles here!

I think this is not a good tradeoff. It seems unlikely anyone would be
using round in a performance-critical context with numbers that are in
a range where an inline compare would be far better, and the costs are
increased code size, decreased performance in useful cases, and
exacerbating timing dependency on data (which is generally a negative
thing).

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.