From owner-freebsd-current@freebsd.org Tue Feb 16 01:01:42 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 87E8B542048 for ; Tue, 16 Feb 2021 01:01:42 +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 4DfjNJ7081z4WTR for ; Tue, 16 Feb 2021 01:01:36 +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 11G11UgN087510 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 15 Feb 2021 17:01:30 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 11G11U5N087509; Mon, 15 Feb 2021 17:01:30 -0800 (PST) (envelope-from sgk) Date: Mon, 15 Feb 2021 17:01:30 -0800 From: Steve Kargl To: Mark Millard Cc: freebsd-current Subject: Re: HEADSUP: math is broken with clang and optimization Message-ID: <20210216010130.GA87472@troutmask.apl.washington.edu> References: <3FD4762E-8C74-4210-8DA9-9FB30E609205.ref@yahoo.com> <3FD4762E-8C74-4210-8DA9-9FB30E609205@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3FD4762E-8C74-4210-8DA9-9FB30E609205@yahoo.com> X-Rspamd-Queue-Id: 4DfjNJ7081z4WTR 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 [-2.99 / 15.00]; RCVD_TLS_ALL(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[128.95.76.21:from]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; SPAMHAUS_ZRD(0.00)[128.95.76.21:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; NEURAL_HAM_SHORT(-0.99)[-0.991]; RCPT_COUNT_TWO(0.00)[2]; R_SPF_NA(0.00)[no SPF record]; FREEMAIL_TO(0.00)[yahoo.com]; 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_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-current]; DMARC_POLICY_SOFTFAIL(0.10)[washington.edu : No valid SPF, No valid DKIM, none] 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, 16 Feb 2021 01:01:42 -0000 On Mon, Feb 15, 2021 at 03:27:08PM -0800, Mark Millard wrote: > > On Mon, Feb 15, 2021 at 01:03:36PM -0800, Steve Kargl wrote: > > > On Mon, Feb 15, 2021 at 12:49:13PM -0800, Steve Kargl wrote: > > > > On Sun, Feb 14, 2021 at 01:59:58PM -0800, Steve Kargl wrote: > > > > > Just a headsup for anyone doing numerical work with > > > > > FreeBSD-current. clang with optimization of -O1 or > > > > > higher produces wrong results. Testing 1 million > > > > > complex values of ccoshf and limiting |z| < 20, > > > > > shows > > > > > > > > > > > > > This is either an in-ling bug or discarding a cast issue. > > > > With everything in the same file so clang has dp_ccosh > > > > available to it when compiling main. > > > > > > > > > > Code builds and works as expected with gcc 10.2and > > > gcc 11.0.0. > > > > > > > Can't find a list of options that is equivalent to -O1, > > so cannot test various optimizations. > > > > Notice that -march=i686 gives the wrong results and > > -march=core2 gives the correct result. Trying -march=i686 > > -msse -msse2 gives the correct result. It seems that > > clang does not understand how the x87 (on i585-freebsd). > > I tried looking around some and got the following > that might be contributing: variations in > __FLT_EVAL_METHOD__ used . . . > > # cc -target i386-unknown-freebsd14.0 -march=i686 -O2 -x c /dev/null -dM -E | egrep "(FLT_EVAL_METHOD|ILP32|LP64)" > #define _ILP32 1 > #define __FLT_EVAL_METHOD__ 2 > #define __ILP32__ 1 > > # cc -target i386-unknown-freebsd14.0 -march=core2 -O2 -x c /dev/null -dM -E | egrep "(FLT_EVAL_METHOD|ILP32|LP64)" > #define _ILP32 1 > #define __FLT_EVAL_METHOD__ 0 > #define __ILP32__ 1 > > # cc -target x86_64-unknown-freebsd14.0 -march=core2 -O2 -x c /dev/null -dM -E | egrep "(FLT_EVAL_METHOD|ILP32|LP64)" > #define _LP64 1 > #define __FLT_EVAL_METHOD__ 0 > #define __LP64__ 1 > > FYI: It does not look like FreeBSD's /usr/include/x86/float.h > matches all the detail: > > #if __ISO_C_VISIBLE >= 1999 > #ifdef __LP64__ > #define FLT_EVAL_METHOD 0 /* no promotions */ > #else > #define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */ > #endif > . . . > #endif > > > For reference: > > # cc -target i386-unknown-freebsd14.0 -O2 -x c /dev/null -dM -E | egrep "(FLT_EVAL_METHOD|ILP32|LP64)" > #define _ILP32 1 > #define __FLT_EVAL_METHOD__ 2 > #define __ILP32__ 1 > > # cc -target x86_64-unknown-freebsd14.0 -O2 -x c /dev/null -dM -E | egrep "(FLT_EVAL_METHOD|ILP32|LP64)" > #define _LP64 1 > #define __FLT_EVAL_METHOD__ 0 > #define __LP64__ 1 > > # cc -target x86_64-unknown-freebsd14.0 -march=i686 -O2 -x c /dev/null -dM -E | grep FLT_EVAL_METHOD | sort > error: unknown target CPU 'i686' > note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, x86-64 > > # cc -v > FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe) > Target: x86_64-unknown-freebsd14.0 > Thread model: posix > InstalledDir: /usr/bin > Doesn't surprise me. gcc knows about freebsd special handling of the i387 on i686-*-freebsd. clang does not. clang: % cc -E -dM -c -march=i686 testf.c | egrep "(FLT_EVAL_METHOD|__ILP32|__LP64)" #define FLT_EVAL_METHOD (-1) #define __FLT_EVAL_METHOD__ 2 #define __ILP32__ 1 gcc10: % gcc10 -E -dM -c -march=i686 testf.c | egrep "(FLT_EVAL_METHOD|__ILP32|__LP64)" #define __FLT_EVAL_METHOD__ 2 #define __FLT_EVAL_METHOD_TS_18661_3__ 2 #define __ILP32__ 1 #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ -- Steve