From owner-freebsd-numerics@freebsd.org Tue Feb 20 03:01:34 2018 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ED94DF1DA66 for ; Tue, 20 Feb 2018 03:01:33 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-yb0-x22e.google.com (mail-yb0-x22e.google.com [IPv6:2607:f8b0:4002:c09::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 92E837C39B for ; Tue, 20 Feb 2018 03:01:33 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: by mail-yb0-x22e.google.com with SMTP id s79-v6so3502345ybs.0 for ; Mon, 19 Feb 2018 19:01:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:from:date:message-id:subject:to; bh=TjK7QF9WLTMpwBxvNFtrVV4p4tietLgcTeSqo6s+DCA=; b=mz8EKIFK1GIdzffjAbzIbpjyFsgt4eB/Eo1bE/lRYBcqzTzTwYRbBkQdrTlJmuRUfj RGEPkaVzUIMs5zXMYMGAuq+MYOh+U8liyjHLr+Ycu18BUhwfkCC9MuYwLwDZCsjJrOPx 5ySoXn5963laVKJCLmvYnHeTTwls1THf9sAfI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=TjK7QF9WLTMpwBxvNFtrVV4p4tietLgcTeSqo6s+DCA=; b=VzoeSpaM7n3wvEumSmaWMP40lsDlSJ/VWSpjt1O8j1+gVPZGjhYQNDOafUh5horyg7 7fBjvHDRhNfbr49FVfr8dXd4/lTkR0axFeiWdT/BPEUub9l697GcLU1hMZe2zIJCd+SE eHVLcxOb+T/EH60FPour3BBavw/18qqn3vu/0dfOhOP3ldQRwHaBsRkSKPL6hN1sjNby VFvdlkZI5ZhtCZRGgLdqi7WnW7cxXwDT0dP6F3rPzTU7Zsc+iwRWhkV35U2RZSVBZTdO VbX9vlq3RpPkkDQJLHSiZTFUCpk3xKg2BjzFcInl52wFuab2m3NiDPmMnhd0XdMKxhXF pPJQ== X-Gm-Message-State: APf1xPCz2alCZK/Pidof24gfhIQxTV5444RwEaPqNdto8q6HNf0+v1Da wjU2mbsMrrj5jk9QmiFqFt82shy0Zi9O3FsyBNUDC5y9 X-Google-Smtp-Source: AH8x226sxIeXXrbTAbi26rojtCuOPLk0EIn0Kf35hbFwqGspT9pYIfiL3mIWP02QyixHuLlog2d9RMiLdMDHXYmRmhM= X-Received: by 10.37.134.197 with SMTP id y5mr11621765ybm.194.1519095692603; Mon, 19 Feb 2018 19:01:32 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a25:dfcb:0:0:0:0:0 with HTTP; Mon, 19 Feb 2018 19:01:02 -0800 (PST) From: Eitan Adler Date: Mon, 19 Feb 2018 19:01:02 -0800 Message-ID: Subject: Marking more functions as pure / const To: freebsd-numerics@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.25 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: Tue, 20 Feb 2018 03:01:34 -0000 There are a few functions that are explicitly marked as "not pure2" (const) but can be marked as pure. The difference between them is "does the function /read/ from global memory?". Is there anything wrong with this diff? Not touched are all the other functions which all seem to at least be __pure if not __pure2. Index: lib/msun/src/math.h =================================================================== --- lib/msun/src/math.h (revision 329611) +++ lib/msun/src/math.h (working copy) @@ -242,11 +242,11 @@ double sinh(double); double tanh(double); double exp(double); -double frexp(double, int *); /* fundamentally !__pure2 */ +double frexp(double, int *) __pure; /* fundamentally !__pure2 */ double ldexp(double, int); double log(double); double log10(double); -double modf(double, double *); /* fundamentally !__pure2 */ +double modf(double, double *) __pure; /* fundamentally !__pure2 */ double pow(double, double); double sqrt(double); @@ -354,7 +354,7 @@ float tanhf(float); float exp2f(float); float expf(float); float expm1f(float); -float frexpf(float, int *); /* fundamentally !__pure2 */ +float frexpf(float, int *) __pure; /* fundamentally !__pure2 */ int ilogbf(float) __pure2; float ldexpf(float, int); float log10f(float); @@ -361,7 +361,7 @@ float log10f(float); float log1pf(float); float log2f(float); float logf(float); -float modff(float, float *); /* fundamentally !__pure2 */ +float modff(float, float *) __pure; /* fundamentally !__pure2 */ float powf(float, float); float sqrtf(float); @@ -461,7 +461,7 @@ long double fmal(long double, long double, long do long double fmaxl(long double, long double) __pure2; long double fminl(long double, long double) __pure2; long double fmodl(long double, long double); -long double frexpl(long double, int *); /* fundamentally !__pure2 */ +long double frexpl(long double, int *) __pure; /* fundamentally !__pure2 */ long double hypotl(long double, long double); int ilogbl(long double) __pure2; long double ldexpl(long double, int); @@ -475,7 +475,7 @@ long double logbl(long double); long double logl(long double); long lrintl(long double); long lroundl(long double); -long double modfl(long double, long double *); /* fundamentally !__pure2 */ +long double modfl(long double, long double *) __pure; /* fundamentally !__pure2 */ long double nanl(const char *) __pure2; long double nearbyintl(long double); long double nextafterl(long double, long double); -- Eitan Adler From owner-freebsd-numerics@freebsd.org Tue Feb 20 05:06:17 2018 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 86731F01E6A for ; Tue, 20 Feb 2018 05:06:17 +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 B2AC282240 for ; Tue, 20 Feb 2018 05:06:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail106.syd.optusnet.com.au (Postfix) with ESMTPS id 1FFBB3C4AAD; Tue, 20 Feb 2018 16:06:13 +1100 (AEDT) Date: Tue, 20 Feb 2018 16:06:13 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Eitan Adler cc: freebsd-numerics@freebsd.org Subject: Re: Marking more functions as pure / const In-Reply-To: Message-ID: <20180220143054.T1999@besplex.bde.org> References: 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=cIaQihWN c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=2S7Sie-zMNKTdtlf6IcA:9 a=CjuIK1q_8ugA:10 X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.25 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: Tue, 20 Feb 2018 05:06:17 -0000 On Mon, 19 Feb 2018, Eitan Adler wrote: > There are a few functions that are explicitly marked as "not pure2" > (const) but can be marked as pure. The difference between them is > "does the function /read/ from global memory?". > > Is there anything wrong with this diff? Not touched are all the other > functions which all seem to at least be __pure if not __pure2. Maybe these functions are even __pure2. Their pointer arg is output-only, and gcc docs only emphasize that functions which have pointer args and examine the data pointed to must not be declared const. Most of the other functions aren't __pure because they have side effects on the FP env. They are further from being __pure2 because they depend on the FP env. I don't like the __pure macro. __pure2 means the gcc-2 syntax for the original __pure macro. __pure was reserved for non-use, but someone used it for something completely different (different syntax and different meaning). Spelling gcc2's __const__ as __pure2 and the subtle difference between __pure2 and the repurposed __pure add to the confusion. > Index: lib/msun/src/math.h > =================================================================== > --- lib/msun/src/math.h (revision 329611) > +++ lib/msun/src/math.h (working copy) > @@ -242,11 +242,11 @@ double sinh(double); > double tanh(double); > > double exp(double); > -double frexp(double, int *); /* fundamentally !__pure2 */ > +double frexp(double, int *) __pure; /* fundamentally !__pure2 */ > ... This comment was written to inhibit futher uses of __pure*. The original version used __pure, but that seemed to be wrong because there are side effects. Now I think it was correct and the comment is wrong. Another comment about __pure2 still only says that __pure2 means that there are no side effects. The only possible side effects are for signaling NaNs, and we don't worry about these for functions like fabs*() and declare fabs*() as __pure2. The only possible impurity is the pointer arg, but it is write-only. The comment is also missing the detail that the FP env affects purity for input. This is a larger source of impurity in practice. The exception flags are not used as often as the rounding mode. The rounding mode being in the FP env means that most math functions do depend on global state, namely the FP env, so are not __pure2. Please check if __pure2 applies to write-only pointer args and use it if possible. Then no comment here is needed. Otherwise, change the comment to say !__pure2 because of the pointer arg. Update the general comment about __pure2. Did it always mean no pointer args? Bruce