From owner-freebsd-toolchain@freebsd.org Tue Sep 8 17:47:24 2020 Return-Path: Delivered-To: freebsd-toolchain@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 7DAC93D12DA; Tue, 8 Sep 2020 17:47:24 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (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 (2048 bits) client-digest SHA256) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BmCK726b0z46DT; Tue, 8 Sep 2020 17:47:22 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 088HlL1G081546 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 8 Sep 2020 10:47:21 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 088HlLNu081545; Tue, 8 Sep 2020 10:47:21 -0700 (PDT) (envelope-from sgk) Date: Tue, 8 Sep 2020 10:47:21 -0700 From: Steve Kargl To: freebsd-toolchain@freebsd.org, freebsd-current@freebsd.org Subject: Re: clang miscompiles OpenLibm on i686-*-freebsd Message-ID: <20200908174721.GA81469@troutmask.apl.washington.edu> References: <20200908021002.GA76325@troutmask.apl.washington.edu> <20200908025513.GA76566@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200908025513.GA76566@troutmask.apl.washington.edu> X-Rspamd-Queue-Id: 4BmCK726b0z46DT X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=washington.edu (policy=none); spf=none (mx1.freebsd.org: domain of sgk@troutmask.apl.washington.edu has no SPF policy when checking 128.95.76.21) smtp.mailfrom=sgk@troutmask.apl.washington.edu X-Spamd-Result: default: False [0.42 / 15.00]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[washington.edu : No valid SPF, No valid DKIM,none]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(0.11)[0.106]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; NEURAL_SPAM_MEDIUM(0.09)[0.093]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(0.22)[0.221]; R_SPF_NA(0.00)[no SPF record]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:73, ipnet:128.95.0.0/16, country:US]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-toolchain,freebsd-current]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Sep 2020 17:47:24 -0000 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: > > > > Interval tested for exp2f: [1,8] > > ulp <= 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 > > > > Note, compiling s_exp2f.c with gcc9 gives the above > result with -O3 -march=i686 -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. > > Note, FreeBSD's libm gives > > % ./tlibm_libm -DEfP exp2 > Interval tested for exp2f: [1,8] > ulp <= 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 > > which is good, but this is compiled with CPUTYPE ?= core2 > in /etc/make.conf. > 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 //VBS #define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval)) /* VBS #ifdef FLT_EVAL_METHOD // Attempt to get strict C99 semantics for assignment with non-C99 compilers. #if FLT_EVAL_METHOD == 0 || __GNUC__ == 0 #define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval)) #else #define STRICT_ASSIGN(type, lval, rval) do { \ volatile type __lval; \ \ if (sizeof(type) >= sizeof(double)) \ (lval) = (rval); \ else { \ __lval = (rval); \ (lval) = __lval; \ } \ } while (0) #endif #endif */ So, STRICT_ASSIGN is broken in Openlibm. I'll be reporting a bug upstream. Apoogies for the noise. -- Steve