From owner-freebsd-current@freebsd.org Tue Feb 9 23:26:40 2021 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6950652F683 for ; Tue, 9 Feb 2021 23:26:40 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DZzYX2SfMz4WjG; Tue, 9 Feb 2021 23:26:40 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "R3" (verified OK)) (Authenticated sender: dim) by smtp.freebsd.org (Postfix) with ESMTPSA id 2548C5878; Tue, 9 Feb 2021 23:26:40 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:470:7a58::5074:79a1:ecee:437d] (unknown [IPv6:2001:470:7a58:0:5074:79a1:ecee:437d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id A8FBB60204; Wed, 10 Feb 2021 00:26:37 +0100 (CET) From: Dimitry Andric Message-Id: <051767C6-85FB-48E8-AFE1-546DC41E8D17@FreeBSD.org> Content-Type: multipart/signed; boundary="Apple-Mail=_0B1E5AAA-12E1-454C-B5BC-E07EFB1F349F"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Subject: Re: [PACTH,libm] hypothl(x) mishandles subnormal numbers. Date: Wed, 10 Feb 2021 00:26:29 +0100 In-Reply-To: <20210209231529.GA59891@troutmask.apl.washington.edu> Cc: FreeBSD Current To: Steve Kargl References: <20210206203929.GA45801@troutmask.apl.washington.edu> <20210206210448.GC45801@troutmask.apl.washington.edu> <20210209231529.GA59891@troutmask.apl.washington.edu> X-Mailer: Apple Mail (2.3445.104.17) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Feb 2021 23:26:40 -0000 --Apple-Mail=_0B1E5AAA-12E1-454C-B5BC-E07EFB1F349F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 10 Feb 2021, at 00:15, Steve Kargl = wrote: >=20 > On Sat, Feb 06, 2021 at 10:32:33PM +0100, Dimitry Andric wrote: >> On 6 Feb 2021, at 22:04, Steve Kargl = wrote: >>>=20 >>> On Sat, Feb 06, 2021 at 12:39:29PM -0800, Steve Kargl wrote: >>>> I've long forgotten by freebsd bugzilla password. >>>> So, if someone would like to submit a bug report, >>>> here's a test program. >>>>=20 >>> Forgot to include that issue was identified from >>> a bug report in the OpenLibm bug mailing list. >>>=20 >>> https://github.com/JuliaMath/openlibm/issues/224 >>=20 >> I put this in . Now the trick is to >> figure out what is going on in e_hypotl.c... :) >>=20 >=20 > This patch fixes the issue. t1 is used to scale the subnormal > numbers. It is generated by scaling the exponent, but that > only works if t1 is 1 not 0. >=20 > Index: src/e_hypotl.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- src/e_hypotl.c (revision 2342) > +++ src/e_hypotl.c (working copy) > @@ -82,7 +82,7 @@ hypotl(long double x, long double y) > man_t manh, manl; > GET_LDBL_MAN(manh,manl,b); > if((manh|manl)=3D=3D0) return a; > - t1=3D0; > + t1=3D1; > SET_HIGH_WORD(t1,ESW(MAX_EXP-2)); /* = t1=3D2^(MAX_EXP-2) */ > b *=3D t1; > a *=3D t1; >=20 Ah, having looked at the glibc code, I had concluded something similar in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D253313#c2, but using INSERT_LDBL80_WORDS(t1,ESW(MAX_EXP-2),0x8000000000000000). Your solution is a lot simpler though. :) Note that to make it work, I also needed to insert a volatile into the INSERT_LDBL80_WORDS() macro. There are more places where this is apparently needed, due to the way recent clang versions tend to over-optimize floating point code at compile time. And specifically for the case where one union field is written, and then another field read, sometimes leading to unexpected results... In any case, I will apply this soon, and also add a test case. Thanks! -Dimitry --Apple-Mail=_0B1E5AAA-12E1-454C-B5BC-E07EFB1F349F Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCYCMaJQAKCRCwXqMKLiCW o73NAJ4qj+xdXqSkJvl1RRpKA7+wd07m2gCeIpUAecU15Z3ZJc2GAEgju9k9xqQ= =UJ9F -----END PGP SIGNATURE----- --Apple-Mail=_0B1E5AAA-12E1-454C-B5BC-E07EFB1F349F--