From owner-freebsd-current@freebsd.org Tue Sep 8 19:12:00 2020 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 F0A5D3D470A; Tue, 8 Sep 2020 19:12:00 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BmFBm4JXRz4JyX; Tue, 8 Sep 2020 19:12:00 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:470:7a58:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "Let's Encrypt Authority X3" (verified OK)) (Authenticated sender: dim) by smtp.freebsd.org (Postfix) with ESMTPSA id 5CBA326778; Tue, 8 Sep 2020 19:12:00 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:470:7a58::a9cd:b64f:c621:a30f] (unknown [IPv6:2001:470:7a58:0:a9cd:b64f:c621:a30f]) (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 45E6E6E98E; Tue, 8 Sep 2020 21:11:58 +0200 (CEST) From: Dimitry Andric Message-Id: <66AE2F5B-F150-4D52-BF43-8F453217FC33@FreeBSD.org> Content-Type: multipart/signed; boundary="Apple-Mail=_FDCF2DD6-2925-4559-98AC-0088A490BB1A"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.15\)) Subject: Re: clang miscompiles OpenLibm on i686-*-freebsd Date: Tue, 8 Sep 2020 21:11:50 +0200 In-Reply-To: <20200908174721.GA81469@troutmask.apl.washington.edu> Cc: freebsd-toolchain@freebsd.org, freebsd-current@freebsd.org To: Steve Kargl References: <20200908021002.GA76325@troutmask.apl.washington.edu> <20200908025513.GA76566@troutmask.apl.washington.edu> <20200908174721.GA81469@troutmask.apl.washington.edu> X-Mailer: Apple Mail (2.3445.104.15) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.33 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, 08 Sep 2020 19:12:01 -0000 --Apple-Mail=_FDCF2DD6-2925-4559-98AC-0088A490BB1A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 8 Sep 2020, at 19:47, Steve Kargl = wrote: >=20 > On Mon, Sep 07, 2020 at 07:55:13PM -0700, Steve Kargl wrote: >> On Mon, Sep 07, 2020 at 07:10:02PM -0700, Steve Kargl wrote: >>>=20 >>> Interval tested for exp2f: [1,8] >>> ulp <=3D 0.5: 0.056% 14072 | 0.056% 14072 >>> 0.5 < ulp < 0.6: 0.000% 8 | 0.056% 14080 >>> 3.0 < ulp < 0.0: 99.944% 25151744 | 100.000% 25165824 >>> Max ulp: 22729.386719 at 1.00195301e+00 >>>=20 >>=20 >> Note, compiling s_exp2f.c with gcc9 gives the above >> result with -O3 -march=3Di686 -m32. So, gcc9 is not >> nearly as bad as clang, but both give bad results. >> Comparing OpenLibm's s_exp2f.c and FreeBSD's s_exp2f.c, >> one sees that the files are almost identical. >>=20 >> Note, FreeBSD's libm gives >>=20 >> % ./tlibm_libm -DEfP exp2 >> Interval tested for exp2f: [1,8] >> ulp <=3D 0.5: 99.959% 25155610 | 99.959% 25155610 >> 0.5 < ulp < 0.6: 0.041% 10214 | 100.000% 25165824 >> Max ulp: 0.500980 at 1.97115958e+00 >>=20 >> which is good, but this is compiled with CPUTYPE ?=3D core2 >> in /etc/make.conf. >>=20 >=20 > I think I've found the problem, and it appears to be > due to a change byt Openlibm developers to the file > math_private.h copied from FreeBSD. Namely, one finds >=20 > //VBS > #define STRICT_ASSIGN(type, lval, rval) ((lval) =3D (rval)) >=20 > /* VBS > #ifdef FLT_EVAL_METHOD > // Attempt to get strict C99 semantics for assignment with non-C99 = compilers. > #if FLT_EVAL_METHOD =3D=3D 0 || __GNUC__ =3D=3D 0 > #define STRICT_ASSIGN(type, lval, rval) ((lval) =3D (rval)) > #else > #define STRICT_ASSIGN(type, lval, rval) do { \ > volatile type __lval; \ > \ > if (sizeof(type) >=3D sizeof(double)) \ > (lval) =3D (rval); \ > else { \ > __lval =3D (rval); \ > (lval) =3D __lval; \ > } \ > } while (0) > #endif > #endif > */ >=20 > So, STRICT_ASSIGN is broken in Openlibm. I'll be reporting > a bug upstream. Apoogies for the noise. Hi Steve, I'm curious what their rationale was, as the commit that changed it is: = https://github.com/JuliaMath/openlibm/commit/f5fb92746715beb0441a60feca202= ee16cb19fc9 with a description of just "Build with gcc"... Maybe they've assumed gcc never needs the volatile approach? -Dimitry --Apple-Mail=_FDCF2DD6-2925-4559-98AC-0088A490BB1A 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 iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCX1fXdgAKCRCwXqMKLiCW o6Z1AJ9iVMo9dPDbDN+OqHdtmVyTH0hXIgCffjTrI+NigtgyIaO1m6gQBYPwnCw= =bsQX -----END PGP SIGNATURE----- --Apple-Mail=_FDCF2DD6-2925-4559-98AC-0088A490BB1A--