From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11164 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix underflow exception in fma and fmal Date: Sun, 19 Mar 2017 04:36:14 +0100 Message-ID: <20170319033613.GO2082@port70.net> 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 1489894588 1600 195.159.176.226 (19 Mar 2017 03:36:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Mar 2017 03:36:28 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-11179-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 19 04:36:23 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 1cpRdm-0008JY-Fj for gllmg-musl@m.gmane.org; Sun, 19 Mar 2017 04:36:22 +0100 Original-Received: (qmail 27948 invoked by uid 550); 19 Mar 2017 03:36:26 -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 27919 invoked from network); 19 Mar 2017 03:36:25 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:11164 Archived-At: another corner case in the freebsd fma code where signaling underflow may be missed for an inexact subnormal result. (fmaf and x86 fma are not affected) --- src/math/fma.c | 7 +++++++ src/math/fmal.c | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/math/fma.c b/src/math/fma.c index 741ccd75..c69918d1 100644 --- a/src/math/fma.c +++ b/src/math/fma.c @@ -279,6 +279,13 @@ static inline double add_and_denormalize(double a, double b, int scale) uhi.i += 1 - (((uhi.i ^ ulo.i) >> 62) & 2); sum.hi = uhi.f; } +#ifdef FE_UNDERFLOW + /* + * Raise underflow manually because scalbn won't do it if all + * lost bits are 0: fma(-0x1p-1000, 0x1.000001p-74, 0x1p-1022) + */ + feraiseexcept(FE_UNDERFLOW); +#endif } return scalbn(sum.hi, scale); } diff --git a/src/math/fmal.c b/src/math/fmal.c index 4506aac6..feb19ec1 100644 --- a/src/math/fmal.c +++ b/src/math/fmal.c @@ -121,6 +121,14 @@ static inline long double add_and_denormalize(long double a, long double b, int bits_lost = -u.i.se - scale + 1; if ((bits_lost != 1) ^ LASTBIT(u)) sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); +#ifdef FE_UNDERFLOW + /* + * Raise underflow manually because scalbnl won't do it if all + * lost bits are 0, e.g.: + * fmal(-0x1p-10000L, 0x1.0000000000001p-6445L, 0x1p-16382L) + */ + feraiseexcept(FE_UNDERFLOW); +#endif } return scalbnl(sum.hi, scale); } -- 2.11.0