mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Damian McGuckin <damianm@esi.com.au>
To: musl@lists.openwall.com
Subject: Re: remquo - underlying logic
Date: Mon, 4 Dec 2017 19:10:17 +1100 (AEDT)	[thread overview]
Message-ID: <alpine.LRH.2.02.1712041657080.4717@key0.esi.com.au> (raw)
In-Reply-To: <20171130211713.GT15263@port70.net>


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


  reply	other threads:[~2017-12-04  8:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30 18:11 Damian McGuckin
2017-11-30 18:59 ` Szabolcs Nagy
2017-11-30 20:29   ` Damian McGuckin
2017-11-30 21:16     ` John Reiser
2017-11-30 21:17     ` Szabolcs Nagy
2017-12-04  8:10       ` Damian McGuckin [this message]
2017-12-06  1:17       ` Damian McGuckin
2017-12-06 10:37         ` Szabolcs Nagy
2017-12-07  1:09           ` Damian McGuckin
2017-12-08  0:42             ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.02.1712041657080.4717@key0.esi.com.au \
    --to=damianm@esi.com.au \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).