mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: [PATCH] fix underflow exception in fma and fmal
Date: Sun, 19 Mar 2017 18:06:08 +0100	[thread overview]
Message-ID: <20170319170607.GS2082@port70.net> (raw)
In-Reply-To: <20170319145340.GS1693@brightrain.aerifal.cx>

* Rich Felker <dalias@libc.org> [2017-03-19 10:53:40 -0400]:
> On Sun, Mar 19, 2017 at 03:39:53PM +0100, Szabolcs Nagy wrote:
> > this case is for nearest rounding mode when the
> > result is in the subnormal range, at this point the
> > result is represented as hi,lo,scale but the final
> > returned value is computed as scalbn(hi,scale)
> > (the last bits of hi are adjusted if required for
> > correct rounding), however scalbn fails to raise
> > underflow if lo!=0 and all lost bits of hi are 0.
> > 
> > the example is such a case: 0x1p-1022 - 0x1.000001p-1074
> > then hi=1-eps,lo=-0x1p-76,scale=-1022 or maybe with
> > shifted scale and exponents, but in the end only one
> > bit is lost from hi which is zero, alternatively i
> > could do scalbn(lo,scale) too to raise underflow.
> 
> That makes sense. I tend to prefer the scalbn(lo,scale) approach if
> there aren't good reasons (performance?) against it, simply because
> it's more self-documenting and less special-cased. But whichever you
> like is fine. BTW we should probably check that scalbn raises inexact
> in all cases it should; I'm not sure what it (especially asm versions)
> does in cases where the scale is smaller than the min exponent.

ok i can do it with scalbn.

generic scalbn is correct and i386 should be correct too:
it does a mul at the end which should raise the flags
(i added tests for this now).

i think we should fix the fma underflow before- vs
after-rounding issue, the current code is only correct
for after-rounding archs (x86, mips, sh) even with the
fix, but doing it correctly is tricky.


      reply	other threads:[~2017-03-19 17:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-19  3:36 Szabolcs Nagy
2017-03-19 14:12 ` Rich Felker
2017-03-19 14:39   ` Szabolcs Nagy
2017-03-19 14:53     ` Rich Felker
2017-03-19 17:06       ` Szabolcs Nagy [this message]

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=20170319170607.GS2082@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).