mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: remquo - underlying logic
Date: Wed, 6 Dec 2017 11:37:09 +0100	[thread overview]
Message-ID: <20171206103708.GA15263@port70.net> (raw)
In-Reply-To: <alpine.LRH.2.02.1712061141550.18308@key0.esi.com.au>

* Damian McGuckin <damianm@esi.com.au> [2017-12-06 12:17:40 +1100]:
> While my exploration with floating point numbers was less than stellar,
> I did notice that when
> 
> 	ex - ey < p (where p is the digits in the significant)
> 
> you can use the
> 
> 	fma
> 
> routine to compute some appropriately rounded/truncated version of the
> quotient for both remquo and fmod. And this appears to not loose any
> precision for the obvious reasons.
> 
> > From my limited testing, the speed gain for this extremely limited range
> of exponent difference is huge over the standard routine in MUSL. I will do
> some more testing and report in detail but it seems to be orders of
> magnitude.
> 
> Somebody might want to comment on that sort of approach.

it's not clear to me how you use fma (x-(int)(x/y)*y ?),
but efficient fma instruction is not available on all
targets and the software implementation can be very slow.
and i suspect such approach would break fenv correctness.

assuming you rely on exact fma result you may need two
different implementation depending on FP_FAST_FMA
(which is currently missing in musl).

(musl is compiled with -std=c99 so x*y+z is not contracted
to fma(x,y,z) automatically when the instruction is
available, you have to add -ffp-contract=fast if that's
what you want, but it might break some code in musl that
relies on exact arithmetics, most math code should work
either way though.)


  reply	other threads:[~2017-12-06 10:37 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
2017-12-06  1:17       ` Damian McGuckin
2017-12-06 10:37         ` Szabolcs Nagy [this message]
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=20171206103708.GA15263@port70.net \
    --to=nsz@port70.net \
    --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).