Re: kargl@freebsd.org, sgk@troutmask.apl.washington.edu, vincenzo.innocente@cern.ch, riemannic@gmail.com, johnmather@sidefx.com

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Wed, 07 Aug 2024 08:41:24 UTC
On Wed, Aug 07, 2024 at 10:07:32AM +0200, Paul Zimmermann wrote:
>        Hi Konstantin,
> 
> > Date: Tue, 6 Aug 2024 17:56:38 +0300
> > From: Konstantin Belousov <kostikbel@gmail.com>
> > Cc: hackers@freebsd.org, numerics@freebsd.org
> > 
> > On Tue, Aug 06, 2024 at 02:56:01PM +0200, Paul Zimmermann wrote:
> > >        Hi,
> > > 
> > > we have updated our comparison with FreeBSD 14.1:
> > > 
> > > https://members.loria.fr/PZimmermann/papers/accuracy.pdf
> > > 
> > > Remaining issues in 14.1:
> > > 
> > > * the powl function is not thread-safe
> > This is for 80-bit long double, am I right?
> 
> yes
> 
> > And it is because of the global vars passing values between functions?
> > 
> > I tried to hack something in https://reviews.freebsd.org/D46237
> 
> thanks. I tried to apply your patch on top of openlibm-0.8.3 (after
> stripping lib/msun). Part of it failed:
> 
> $ patch -p1 -i /tmp/D46237.diff 
> patching file ld80/e_powl.c
> Hunk #1 FAILED at 23.
> Hunk #2 FAILED at 42.
> Hunk #3 succeeded at 85 (offset -41 lines).
> Hunk #4 succeeded at 100 (offset -41 lines).
> Hunk #5 succeeded at 135 (offset -41 lines).
> Hunk #6 succeeded at 158 (offset -41 lines).
> Hunk #7 succeeded at 189 (offset -41 lines).
> 
> $ cat ld80/e_powl.c.rej 
> --- ld80/e_powl.c
> +++ ld80/e_powl.c
> @@ -23,10 +23,10 @@
>   *  P[0] x^n  +  P[1] x^(n-1)  +  ...  +  P[n]
>   */
>  static inline long double
> -__polevll(long double x, long double *PP, int n)
> +__polevll(long double x, const long double *PP, int n)
>  {
>  	long double y;
> -	long double *P;
> +	const long double *P;
>  
>  	P = PP;
>  	y = *P++;
> @@ -42,10 +42,10 @@
>   *  x^n  +  P[0] x^(n-1)  +  P[1] x^(n-2)  +  ...  +  P[n]
>   */
>  static inline long double
> -__p1evll(long double x, long double *PP, int n)
> +__p1evll(long double x, const long double *PP, int n)
>  {
>  	long double y;
> -	long double *P;
> +	const long double *P;
>  
>  	P = PP;
>  	n -= 1;
> 
> Also I git compiler warnings (maybe due to the rejected part):
> 
> ld80/e_powl.c: In function ‘powl’:
> ld80/e_powl.c:374:29: warning: passing argument 2 of ‘__polevll’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
>   374 | w = x * ( z * __polevll( x, P, 3 ) / __p1evll( x, Q, 3 ) );
>       |                             ^
Yes, we have some restructuring there, quite recent.

Anyway, the main part of the patch is the marking of the statics with
thread local.

> 
> Apart from that, various tests I did seem to indicate the multi-thread issue
> has gone, thanks!
> 
Thank you for the testing.