From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11172 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix underflow exception in fma and fmal Date: Sun, 19 Mar 2017 18:06:08 +0100 Message-ID: <20170319170607.GS2082@port70.net> References: <20170319033613.GO2082@port70.net> <20170319141249.GR1693@brightrain.aerifal.cx> <20170319143953.GQ2082@port70.net> <20170319145340.GS1693@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1489943187 31344 195.159.176.226 (19 Mar 2017 17:06:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Mar 2017 17:06:27 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-11187-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 19 18:06:20 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1cpeHY-0007HT-Jz for gllmg-musl@m.gmane.org; Sun, 19 Mar 2017 18:06:16 +0100 Original-Received: (qmail 23999 invoked by uid 550); 19 Mar 2017 17:06:20 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23978 invoked from network); 19 Mar 2017 17:06:20 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <20170319145340.GS1693@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:11172 Archived-At: * Rich Felker [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.