From owner-freebsd-numerics@freebsd.org Sat May 13 19:14:57 2017 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6E1E0D6BFF6 for ; Sat, 13 May 2017 19:14:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 599CBA9C for ; Sat, 13 May 2017 19:14:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: by mailman.ysv.freebsd.org (Postfix) id 56163D6BFF4; Sat, 13 May 2017 19:14:57 +0000 (UTC) Delivered-To: numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 52341D6BFF3; Sat, 13 May 2017 19:14:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail106.syd.optusnet.com.au (mail106.syd.optusnet.com.au [211.29.132.42]) by mx1.freebsd.org (Postfix) with ESMTP id 10ACDA9B; Sat, 13 May 2017 19:14:56 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from besplex.bde.org (c122-106-153-191.carlnfd1.nsw.optusnet.com.au [122.106.153.191]) by mail106.syd.optusnet.com.au (Postfix) with ESMTPS id 6F0963C6D9F; Sun, 14 May 2017 05:14:54 +1000 (AEST) Date: Sun, 14 May 2017 05:14:53 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Dimitry Andric cc: sgk@troutmask.apl.washington.edu, freebsd-hackers@freebsd.org, numerics@freebsd.org Subject: Re: catrig[fl].c and inexact In-Reply-To: Message-ID: <20170514043645.G2059@besplex.bde.org> References: <20170512215654.GA82545@troutmask.apl.washington.edu> <20170513103208.M845@besplex.bde.org> <20170513060803.GA84399@troutmask.apl.washington.edu> <20170513162153.GB88653@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=VbSHBBh9 c=1 sm=1 tr=0 a=Tj3pCpwHnMupdyZSltBt7Q==:117 a=Tj3pCpwHnMupdyZSltBt7Q==:17 a=kj9zAlcOel0A:10 a=Y88NXTGeRKpz0WgPRmcA:9 a=CjuIK1q_8ugA:10 X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 May 2017 19:14:57 -0000 On Sat, 13 May 2017, Dimitry Andric wrote: > On 13 May 2017, at 18:21, Steve Kargl wrote: >> >> On Sat, May 13, 2017 at 03:08:26PM +0200, Dimitry Andric wrote: > ... >> >>> Using the full catrig.c and -O3, I tried gcc 4.2.1, 4.7.4, 4.8.5, 4.9.4, >>> 5.4.0, 6.3.0 and 7.0.1, in addition to clang 3.4.1, 3.8.0, 3.9.1, 4.0.0 >>> and 5.0.0. >> >> Thanks for checking. I reduced catrig.c to a small self-contained >> program and indeed I was getting the desired addition of 1 + tiny >> to raise FE_INEXACT. I suppose that I'll need to add an appropriate >> -Wno-foo to my CFLAGS line to suppress the spurious warning, which >> might be tricky because -Wunused is one option I'ld like to have. > > The following also gets rid of the warnings: > > Index: lib/msun/src/catrig.c > =================================================================== > --- lib/msun/src/catrig.c (revision 318032) > +++ lib/msun/src/catrig.c (working copy) > @@ -37,7 +37,7 @@ > #define isinf(x) (fabs(x) == INFINITY) > #undef isnan > #define isnan(x) ((x) != (x)) > -#define raise_inexact() do { volatile float junk = 1 + tiny; } while(0) > +#define raise_inexact() do { volatile float junk __unused = 1 + tiny; } while(0) > #undef signbit > #define signbit(x) (__builtin_signbit(x)) > ... > > If you are OK with that, I will commit it later today. It is what I said was best yeseterday :-). Except, __unused is an obfuscation meaning __used. I couldn't get __used to work today either. It works with static variables, but for auto variables it generates "'__used__' attribute ignored" for both clang-3.9.0 and gcc-4.2.1, even without any -W flags to ask for excessive warnings. Today I looked at the macro used(expr), which would be used like used(1 + tiny) for inexact, used(huge * huge) for overflow, and used(tiny * tiny) for underflow. The difficulty is to declare the variable to hold the result, especially since we don't want this variable to be in memory. Also in some cases, we would like to return the result. For overflow, we can do either: ({ volatile float junk __unused = huge * huge; INFINITY; }) or ({ __typeof(huge) r; STRICT_ASSIGN(..., huge * huge); r; }) with different tradoffs (the second is broken if r is not used and there is no volatile hidden in STRICT_ASSIGN()), or better, only load huge once (float t = huge; junk = t * t;). Bruce