math: Use asinf from CORE-MATH

The CORE-MATH implementation is correctly rounded (for any rounding mode)
and shows slight better performance to the generic asinf.

The code was adapted to glibc style and to use the definition of
math_config.h (to handle errno, overflow, and underflow).

Benchtest on x64_64 (Ryzen 9 5900X, gcc 14.2.1), aarch64 (Neoverse-N1,
gcc 13.3.1), and powerpc (POWER10, gcc 13.2.1):

Latency                      master        patched   improvement
x86_64                      42.8237        35.2460        17.70%
x86_64v2                    43.3711        35.9406        17.13%
x86_64v3                    35.0335        30.5744        12.73%
i686                       213.8780        104.4710       51.15%
aarch64 (Neoverse)          17.2937        13.6025        21.34%
power10                     12.0227        7.4241         38.25%

reciprocal-throughput        master        patched   improvement
x86_64                      13.6770        15.5231       -13.50%
x86_64v2                    13.8722        16.0446       -15.66%
x86_64v3                    13.6211        13.2753         2.54%
i686                       186.7670        45.4388        75.67%
aarch64 (Neoverse)          9.96089        9.39285         5.70%
power10                      4.9862        3.7819         24.15%

Signed-off-by: Alexei Sibidanov <sibid@uvic.ca>
Signed-off-by: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Signed-off-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
Adhemerval Zanella 2024-11-13 13:48:14 -03:00
parent 673e6fe110
commit 5fb4b566ef
27 changed files with 124 additions and 214 deletions

View file

@ -302,3 +302,7 @@ sysdeps/ieee754/flt-32/e_acoshf.c:
(src/binary32/acosh/acoshf.c in CORE-MATH) (src/binary32/acosh/acoshf.c in CORE-MATH)
- The code was adapted to use glibc code style and internal - The code was adapted to use glibc code style and internal
functions to handle errno, overflow, and underflow. functions to handle errno, overflow, and underflow.
sysdeps/ieee754/flt-32/e_asinf.c:
(src/binary32/asin/asinf.c in CORE-MATH)
- The code was adapted to use glibc code style and internal
functions to handle errno, overflow, and underflow.

View file

@ -71,7 +71,6 @@ ldouble: 2
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_advsimd": Function: "asin_advsimd":
@ -80,7 +79,6 @@ float: 2
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_sve": Function: "asin_sve":
@ -89,12 +87,10 @@ float: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -35,22 +35,18 @@ ldouble: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -27,19 +27,15 @@ double: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
Function: "asinh": Function: "asinh":
double: 3 double: 3

View file

@ -9,7 +9,6 @@ double: 2
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -43,19 +43,15 @@ float: 1
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -25,19 +25,15 @@ Function: "acosh_upward":
double: 2 double: 2
Function: "asin": Function: "asin":
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 1 double: 1
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -25,19 +25,15 @@ Function: "acosh_upward":
double: 2 double: 2
Function: "asin": Function: "asin":
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 1 double: 1
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -43,19 +43,15 @@ float: 1
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -1,38 +0,0 @@
/*
* Public domain.
*/
#include <machine/asm.h>
#include <i386-math-asm.h>
#include <libm-alias-finite.h>
RCSID("$NetBSD: $")
.section .rodata.cst4,"aM",@progbits,4
DEFINE_FLT_MIN
#ifdef PIC
# define MO(op) op##@GOTOFF(%ecx)
#else
# define MO(op) op
#endif
.text
/* asin = atan (x / sqrt(1 - x^2)) */
ENTRY(__ieee754_asinf)
#ifdef PIC
LOAD_PIC_REG (cx)
#endif
flds 4(%esp) /* x */
fld %st
fmul %st(0) /* x^2 */
fld1
fsubp /* 1 - x^2 */
fsqrt /* sqrt (1 - x^2) */
fpatan
FLT_CHECK_FORCE_UFLOW
ret
END (__ieee754_asinf)
libm_alias_finite (__ieee754_asinf, __asinf)

View file

@ -80,7 +80,6 @@ ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 1 double: 1
float: 1
float128: 2 float128: 2
ldouble: 1 ldouble: 1

View file

@ -80,7 +80,6 @@ ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 1 double: 1
float: 1
float128: 2 float128: 2
ldouble: 1 ldouble: 1

View file

@ -1,105 +1,131 @@
/* e_asinf.c -- float version of e_asin.c. /* Correctly-rounded arc-sine function for binary32 value.
*/
/* Copyright (c) 2023-2024 Alexei Sibidanov.
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/* The original version of this file was copied from the CORE-MATH
Modifications for single precision expansion are project (file src/binary32/asin/asinf.c, revision bc385c2).
Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov>
and are incorporated herein by permission of the author. The author
reserves the right to distribute this material elsewhere under different
copying permissions. These modifications are distributed here under
the following terms:
This library is free software; you can redistribute it and/or Permission is hereby granted, free of charge, to any person obtaining a copy
modify it under the terms of the GNU Lesser General Public of this software and associated documentation files (the "Software"), to deal
License as published by the Free Software Foundation; either in the Software without restriction, including without limitation the rights
version 2.1 of the License, or (at your option) any later version. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
This library is distributed in the hope that it will be useful, The above copyright notice and this permission notice shall be included in all
but WITHOUT ANY WARRANTY; without even the implied warranty of copies or substantial portions of the Software.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
License along with this library; if not, see IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
<https://www.gnu.org/licenses/>. */ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#if defined(LIBM_SCCS) && !defined(lint) #include <stdint.h>
static char rcsid[] = "$NetBSD: e_asinf.c,v 1.5 1995/05/12 04:57:25 jtc Exp $"; #include <errno.h>
#endif
#include <float.h>
#include <math.h>
#include <math_private.h>
#include <math-underflow.h>
#include <libm-alias-finite.h> #include <libm-alias-finite.h>
#include "math_config.h"
static const float static __attribute__ ((noinline)) float
one = 1.0000000000e+00, /* 0x3F800000 */ as_special (float x)
huge = 1.000e+30,
pio2_hi = 1.57079637050628662109375f,
pio2_lo = -4.37113900018624283e-8f,
pio4_hi = 0.785398185253143310546875f,
/* asin x = x + x^3 p(x^2)
-0.5 <= x <= 0.5;
Peak relative error 4.8e-9 */
p0 = 1.666675248e-1f,
p1 = 7.495297643e-2f,
p2 = 4.547037598e-2f,
p3 = 2.417951451e-2f,
p4 = 4.216630880e-2f;
float __ieee754_asinf(float x)
{ {
float t,w,p,q,c,r,s; uint32_t ax = asuint (x) << 1;
int32_t hx,ix; if (ax > (0xffu << 24))
GET_FLOAT_WORD(hx,x); return x + x; /* nan */
ix = hx&0x7fffffff; return __math_invalidf (0.0);
if(ix==0x3f800000) { }
/* asin(1)=+-pi/2 with inexact */
return x*pio2_hi+x*pio2_lo; static double
} else if(ix> 0x3f800000) { /* |x|>= 1 */ poly12 (double z, const double *c)
return (x-x)/(x-x); /* asin(|x|>1) is NaN */ {
} else if (ix<0x3f000000) { /* |x|<0.5 */ double z2 = z * z;
if(ix<0x32000000) { /* if |x| < 2**-27 */ double z4 = z2 * z2;
math_check_force_underflow (x); double c0 = c[0] + z * c[1];
if(huge+x>one) return x;/* return x with inexact if x!=0*/ double c2 = c[2] + z * c[3];
} else { double c4 = c[4] + z * c[5];
t = x*x; double c6 = c[6] + z * c[7];
w = t * (p0 + t * (p1 + t * (p2 + t * (p3 + t * p4)))); double c8 = c[8] + z * c[9];
return x+x*w; double c10 = c[10] + z * c[11];
} c0 += c2 * z2;
} c4 += c6 * z2;
/* 1> |x|>= 0.5 */ c8 += z2 * c10;
w = one-fabsf(x); c0 += z4 * (c4 + z4 * c8);
t = w*0.5f; return c0;
p = t * (p0 + t * (p1 + t * (p2 + t * (p3 + t * p4)))); }
s = sqrtf(t);
if(ix>=0x3F79999A) { /* if |x| > 0.975 */ float
t = pio2_hi-(2.0f*(s+s*p)-pio2_lo); __ieee754_asinf (float x)
} else { {
int32_t iw; const double pi2 = 0x1.921fb54442d18p+0;
w = s; double xs = x;
GET_FLOAT_WORD(iw,w); double r;
SET_FLOAT_WORD(w,iw&0xfffff000); uint32_t ax = asuint (x) << 1;
c = (t-w*w)/(s+w); if (__glibc_unlikely (ax > 0x7f << 24))
r = p; return as_special(x);
p = 2.0f*s*r-(pio2_lo-2.0f*c); if (__glibc_likely (ax < 0x7ec29000u))
q = pio4_hi-2.0f*w; {
t = pio4_hi-(p-q); if (__glibc_unlikely (ax < 115 << 24))
} return fmaf (x, 0x1p-25, x);
if(hx>0) return t; else return -t; static const double b[] =
{
0x1.0000000000005p+0, 0x1.55557aeca105dp-3, 0x1.3314ec3db7d12p-4,
0x1.775738a5a6f92p-5, 0x1.5d5f7ce1c8538p-8, 0x1.605c6d58740fp-2,
-0x1.5728b732d73c6p+1, 0x1.f152170f151ebp+3, -0x1.f962ea3ca992ep+5,
0x1.71971e17375ap+7, -0x1.860512b4ba23p+8, 0x1.26a3b8d4bdb14p+9,
-0x1.36f2ea5698b51p+9, 0x1.b3d722aebfa2ep+8, -0x1.6cf89703b1289p+7,
0x1.1518af6a65e2dp+5
};
double z = xs;
double z2 = z * z;
double z4 = z2 * z2;
double z8 = z4 * z4;
double z16 = z8 * z8;
r = z * ((((b[0] + z2 * b[1]) + z4 * (b[2] + z2 * b[3]))
+ z8 * ((b[4] + z2 * b[5]) + z4 * (b[6] + z2 * b[7])))
+ z16 * (((b[8] + z2 * b[9]) + z4 * (b[10] + z2 * b[11]))
+ z8 * ((b[12] + z2 * b[13])
+ z4 * (b[14] + z2 * b[15]))));
float ub = r;
float lb = r - z * 0x1.efa8ebp-31;
if (ub == lb)
return ub;
}
if (ax < (0x7eu << 24))
{
static const double c[] =
{
0x1.555555555529cp-3, 0x1.333333337e0ddp-4, 0x1.6db6db3b4465ep-5,
0x1.f1c72e13ac306p-6, 0x1.6e89cebe06bc4p-6, 0x1.1c6dcf5289094p-6,
0x1.c6dbbcc7c6315p-7, 0x1.8f8dc2615e996p-7, 0x1.a5833b7bf15e8p-8,
0x1.43f44ace1665cp-6, -0x1.0fb17df881c73p-6, 0x1.07520c026b2d6p-5
};
double z = xs;
double z2 = z * z;
double c0 = poly12 (z2, c);
r = z + (z * z2) * c0;
}
else
{
if (__glibc_unlikely (ax == 0x7e55688au))
return copysignf (0x1.75b8a2p-1f, x) + copysignf (0x1p-26f, x);
if (__glibc_unlikely (ax == 0x7e107434u))
return copysignf (0x1.1f4b64p-1f, x) + copysignf (0x1p-26f, x);
double bx = fabs (xs);
double z = 1.0 - bx;
double s = sqrt (z);
static const double c[] =
{
0x1.6a09e667f3bcbp+0, 0x1.e2b7dddff2db9p-4, 0x1.b27247ab42dbcp-6,
0x1.02995cc4e0744p-7, 0x1.5ffb0276ec8eap-9, 0x1.033885a928decp-10,
0x1.911f2be23f8c7p-12, 0x1.4c3c55d2437fdp-13, 0x1.af477e1d7b461p-15,
0x1.abd6bdff67dcbp-15, -0x1.1717e86d0fa28p-16, 0x1.6ff526de46023p-16
};
r = pi2 - s * poly12 (z, c);
r = copysign (r, xs);
}
return r;
} }
libm_alias_finite (__ieee754_asinf, __asinf) libm_alias_finite (__ieee754_asinf, __asinf)

View file

@ -35,22 +35,18 @@ ldouble: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -7,7 +7,6 @@ Function: "acosh":
double: 2 double: 2
Function: "asin": Function: "asin":
float: 1
Function: "asinh": Function: "asinh":
double: 1 double: 1

View file

@ -27,19 +27,15 @@ double: 2
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -35,22 +35,18 @@ ldouble: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -27,19 +27,15 @@ double: 2
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -31,19 +31,15 @@ float: 1
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asin_upward": Function: "asin_upward":
double: 1 double: 1
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -71,25 +71,21 @@ float: 1
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
float128: 1 float128: 1
ldouble: 2 ldouble: 2
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
float128: 2 float128: 2
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
float128: 1 float128: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
float128: 2 float128: 2
ldouble: 2 ldouble: 2

View file

@ -39,22 +39,18 @@ float: 1
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -35,22 +35,18 @@ ldouble: 2
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -35,22 +35,18 @@ ldouble: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -35,22 +35,18 @@ ldouble: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -13,11 +13,9 @@ Function: "acosh_towardzero":
double: 2 double: 2
Function: "asin": Function: "asin":
float: 1
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
Function: "asinh": Function: "asinh":
double: 2 double: 2

View file

@ -35,22 +35,18 @@ ldouble: 3
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
ldouble: 2 ldouble: 2
Function: "asinh": Function: "asinh":

View file

@ -107,25 +107,21 @@ ldouble: 2
Function: "asin": Function: "asin":
double: 1 double: 1
float: 1
float128: 1 float128: 1
ldouble: 1 ldouble: 1
Function: "asin_downward": Function: "asin_downward":
double: 1 double: 1
float: 1
float128: 2 float128: 2
ldouble: 2 ldouble: 2
Function: "asin_towardzero": Function: "asin_towardzero":
double: 1 double: 1
float: 1
float128: 1 float128: 1
ldouble: 1 ldouble: 1
Function: "asin_upward": Function: "asin_upward":
double: 2 double: 2
float: 1
float128: 2 float128: 2
ldouble: 1 ldouble: 1