From nobody Fri Nov 05 23:43:26 2021 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id AD3131847EB0 for ; Fri, 5 Nov 2021 23:43:29 +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 4HmHBm3Pzjz3KgR; Fri, 5 Nov 2021 23:43:28 +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 1A5NhQBd027499 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 5 Nov 2021 16:43:26 -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 1A5NhQOf027498; Fri, 5 Nov 2021 16:43:26 -0700 (PDT) (envelope-from sgk) Date: Fri, 5 Nov 2021 16:43:26 -0700 From: Steve Kargl To: Dimitry Andric Cc: freebsd-current@freebsd.org, lwhsu@freebsd.org Subject: Re: WHY? commit ac76bc1145dd7f4476e5d982ce8f355f71015713 Message-ID: <20211105234326.GA27491@troutmask.apl.washington.edu> References: <20211105201323.GA26765@troutmask.apl.washington.edu> <34FEBFCC-1CD6-48CB-BA2A-7A2BBD6B4EA1@FreeBSD.org> <20211105221446.GA27181@troutmask.apl.washington.edu> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211105221446.GA27181@troutmask.apl.washington.edu> X-Rspamd-Queue-Id: 4HmHBm3Pzjz3KgR 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 [-1.00 / 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]; NEURAL_HAM_MEDIUM(-1.00)[-0.997]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(1.00)[1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; 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)[]; SUBJECT_HAS_QUESTION(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-ThisMailContainsUnwantedMimeParts: N On Fri, Nov 05, 2021 at 03:14:46PM -0700, Steve Kargl wrote: > On Fri, Nov 05, 2021 at 10:32:26PM +0100, Dimitry Andric wrote: > > On 5 Nov 2021, at 21:13, Steve Kargl wrote: > > > > > > Why was this committed? > > > > > > commit ac76bc1145dd7f4476e5d982ce8f355f71015713 > > > Author: Dimitry Andric > > > Date: Tue Feb 9 22:06:51 2021 +0100 > > > > > > Fix lib/msun's ctrig_test/test_inf_inputs test case with clang >= 10 > > > > > > This sprinkles a few strategic volatiles in an attempt to defeat clang's > > > optimization interfering with the expected floating-point exception > > > flags. > > > > > > There is nothing, and I mean, nothing strategic about "sprinkling" > > > volatile onto the declaration of "float x, y, h;" These variables > > > are referenced in all floating pointing operations in the file, > > > which means that there are needless reloading of x, y, and h > > > from memory. > > > > There was more context in https://bugs.freebsd.org/244732, but the gist > > was that with clang >= 10, ctanh() and ctanhf() had FE_INVALID set after > > calling them with {inf,inf}. The reasons for this were obscure to me at > > the time, since it regressed with an llvm commit that seemed to have > > very little to do with floating point. > > > > However, in 3b00222f156d we added -fp-exception-behavior=maytrap to > > clang's compile flags for lib/msun, for https://bugs.freebsd.org/254911, > > to force it to use stricter floating point semantics. This turns out to > > also make the admittedly ugly volatile fixes unnecessary. > > > > So I have reverted ac76bc1145dd (minus the ctrig_test.c part) in: > > https://cgit.freebsd.org/src/commit/?id=e2157cd0000f6dbb6465d7a885f2dcfd4d3596cb > > > > Thanks for the explanation! This would indeed be strange. > The evaluation of ctanhf does not invoke ccoshf(z). > > The relevant section of code from s_ctanh.c (similar code in s_ctanhf.c) > is > > if (ix >= 0x7ff00000) { > if ((ix & 0xfffff) | lx) /* x is NaN */ > return (CMPLX(nan_mix(x, y), > y == 0 ? y : nan_mix(x, y))); > SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */ > return (CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y)))); > } > > The testcase should get to the second return statement. So, > either isinf(y) or copysign(0, inf) was raising the exception. > I just scanned the llvm report pointed to in the FreeBSD bug report. The llvm report discusses changes in speculative execution. If clang was evaluating isinf(y) and either of sin(y) or cos(y), speculatively, then yes, FE_INVALID will be raised. % tlibm_libm -e cos cosf( 0) = 1. Got no exception. Expected 1 without exception. cosf(-0) = 1. Got no exception. Expected 1 without exception. cosf( inf) = nan. Got FE_INVALID. Expected nan with FE_INVALID. cosf(-inf) = nan. Got FE_INVALID. Expected nan with FE_INVALID. cos( 0) = 1. Got no exception. Expected 1 without exception. cos(-0) = 1. Got no exception. Expected 1 without exception. cos( inf) = nan. Got FE_INVALID. Expected nan with FE_INVALID. cos(-inf) = nan. Got FE_INVALID. Expected nan with FE_INVALID. cosl( 0) = 1. Got no exception. Expected 1 without exception. cosl(-0) = 1. Got no exception. Expected 1 without exception. cosl( inf) = nan. Got FE_INVALID. Expected nan with FE_INVALID. cosl(-inf) = nan. Got FE_INVALID. Expected nan with FE_INVALID. -- Steve