[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
```Message-ID: <alpine.LRH.2.02.1712041657080.4717@key0.esi.com.au>
Date: Mon, 4 Dec 2017 19:10:17 +1100 (AEDT)
From: Damian McGuckin <damianm@....com.au>
To: musl@...ts.openwall.com
Subject: Re: remquo - underlying logic

Floats are not going to be faster for remquo(x, y, &q) except for a very
small range where

1 < x / y < 1000 (or so)

But I was hoping for only a moderate overhead.

And John Reiser mentioned

> The range of a floating-point exponent will limit the applicability.

No.

> Packing and unpacking floating-point format (logb, scalb, etc.) are
> non-trivial costs, as are mucking around with NaN, +inf, -inf,
> denormals, etc.

Not really.

> The "big-O" efficiency is the same: find the difference in exponents,
> scale both operands to have the same exponent,

The above are trivial compared to the operation where you

> perform "ordinary long division" with the number of steps equal to the
> difference in exponents; take care to preserve enough precision.

This is the killer. On a Xeon, the floating point alternative is generally
a factor of 4-6 worse. Actually, in the domain

y * 2^(p) < x < 2^(w-1)

where w is the word size in bits, the penalty is higher still, about 10.
but after that it drops down to a factor of 4 and increases slowly to a
factor of 6 where the difference in exponents is the same as the bias
of the exponent.

I must admit that I found the penalty incredible. A bit scary that faking
floating point is so much faster, although admittedly with quite simple
operations.

The only thing is that the code is infinitely more readable, an important
but not the dominant concern.

An interesting exercise, albiet a bit fruitless.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer
```

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