Message ID | 20250131191844.2582716-14-adhemerval.zanella@linaro.org |
---|---|
State | New |
Headers | show |
Series | Add c23 CORE-MATH binary32 implementations to libm | expand |
I confirm all binary32 inputs are correctly rounded for all rounding modes on x86-64, thank you! Paul > From: Adhemerval Zanella <adhemerval.zanella@linaro.org> > Cc: DJ Delorie <dj@redhat.com>, > Joseph Myers <josmyers@redhat.com>, > Paul Zimmermann <Paul.Zimmermann@inria.fr>, > Alexei Sibidanov <sibid@uvic.ca> > Date: Fri, 31 Jan 2025 16:17:17 -0300 > > The CORE-MATH implementation is correctly rounded (for any rounding mode) > and shows better performance to the generic sinpif. > > 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 47.5710 38.4455 19.18% > x86_64v2 46.8828 40.7563 13.07% > x86_64v3 44.0034 34.1497 22.39% > aarch64 (Neoverse) 19.2493 14.1968 26.25% > power8 23.5312 16.3854 30.37% > power10 22.6485 10.2888 54.57% > > reciprocal-throughput master patched improvement > x86_64 21.8858 11.6717 46.67% > x86_64v2 22.0620 11.9853 45.67% > x86_64v3 21.5653 11.3291 47.47% > aarch64 (Neoverse) 13.0615 6.5499 49.85% > power8 16.2030 6.9580 57.06% > power10 12.8911 4.2858 66.75% > --- > SHARED-FILES | 4 + > sysdeps/aarch64/libm-test-ulps | 4 - > sysdeps/arc/fpu/libm-test-ulps | 4 - > sysdeps/arc/nofpu/libm-test-ulps | 1 - > sysdeps/arm/libm-test-ulps | 4 - > sysdeps/hppa/fpu/libm-test-ulps | 4 - > sysdeps/i386/fpu/libm-test-ulps | 4 - > .../i386/i686/fpu/multiarch/libm-test-ulps | 4 - > sysdeps/ieee754/flt-32/s_sinpif.c | 134 ++++++++++++++++++ > sysdeps/loongarch/lp64/libm-test-ulps | 4 - > sysdeps/mips/mips64/libm-test-ulps | 4 - > sysdeps/or1k/fpu/libm-test-ulps | 4 - > sysdeps/or1k/nofpu/libm-test-ulps | 1 - > sysdeps/powerpc/fpu/libm-test-ulps | 4 - > sysdeps/riscv/nofpu/libm-test-ulps | 1 - > sysdeps/riscv/rvd/libm-test-ulps | 4 - > sysdeps/s390/fpu/libm-test-ulps | 4 - > sysdeps/sparc/fpu/libm-test-ulps | 4 - > sysdeps/x86_64/fpu/libm-test-ulps | 4 - > 19 files changed, 138 insertions(+), 59 deletions(-) > create mode 100644 sysdeps/ieee754/flt-32/s_sinpif.c > > diff --git a/SHARED-FILES b/SHARED-FILES > index 3ce38d1542..c108f3b308 100644 > --- a/SHARED-FILES > +++ b/SHARED-FILES > @@ -354,3 +354,7 @@ sysdeps/ieee754/flt-32/s_cospif.c: > (src/binary32/cospi/cospif.c in CORE-MATH) > - the code was adapted to use glibc code style and internal > functions to handle errno, overflow, and underflow. > +sysdeps/ieee754/flt-32/s_sinpif.c: > + (src/binary32/sinpi/sinpif.c in CORE-MATH) > + - the code was adapted to use glibc code style and internal > + functions to handle errno, overflow, and underflow. > diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps > index a15f3effa0..c6c93aa0e4 100644 > --- a/sysdeps/aarch64/libm-test-ulps > +++ b/sysdeps/aarch64/libm-test-ulps > @@ -1610,7 +1610,6 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_advsimd": > @@ -1619,7 +1618,6 @@ float: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_sve": > @@ -1628,12 +1626,10 @@ float: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps > index f2acbf453e..65ebf6f9a0 100644 > --- a/sysdeps/arc/fpu/libm-test-ulps > +++ b/sysdeps/arc/fpu/libm-test-ulps > @@ -1101,19 +1101,15 @@ double: 3 > > Function: "sinpi": > double: 2 > -float: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > > Function: "sinpi_upward": > double: 2 > -float: 3 > > Function: "tan": > double: 1 > diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps > index 8716e5d29e..3ba4f01cbf 100644 > --- a/sysdeps/arc/nofpu/libm-test-ulps > +++ b/sysdeps/arc/nofpu/libm-test-ulps > @@ -265,7 +265,6 @@ double: 2 > > Function: "sinpi": > double: 2 > -float: 2 > > Function: "tanh": > double: 2 > diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps > index 647f92944c..f887712d8e 100644 > --- a/sysdeps/arm/libm-test-ulps > +++ b/sysdeps/arm/libm-test-ulps > @@ -1097,19 +1097,15 @@ double: 3 > > Function: "sinpi": > double: 2 > -float: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > > Function: "sinpi_upward": > double: 2 > -float: 3 > > Function: "tan_downward": > double: 1 > diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps > index 88f7701c0e..10f7f2ebde 100644 > --- a/sysdeps/hppa/fpu/libm-test-ulps > +++ b/sysdeps/hppa/fpu/libm-test-ulps > @@ -1123,19 +1123,15 @@ double: 3 > > Function: "sinpi": > double: 2 > -float: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > > Function: "sinpi_upward": > double: 2 > -float: 3 > > Function: "tan": > double: 1 > diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps > index 39066956b0..77aa7155db 100644 > --- a/sysdeps/i386/fpu/libm-test-ulps > +++ b/sysdeps/i386/fpu/libm-test-ulps > @@ -1691,25 +1691,21 @@ ldouble: 5 > > Function: "sinpi": > double: 2 > -float: 2 > float128: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > float128: 2 > ldouble: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > float128: 2 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > float128: 2 > ldouble: 2 > > diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps > index a8c4723850..7168d577d8 100644 > --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps > +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps > @@ -1696,25 +1696,21 @@ ldouble: 5 > > Function: "sinpi": > double: 2 > -float: 2 > float128: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > float128: 2 > ldouble: 3 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > float128: 2 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > float128: 2 > ldouble: 2 > > diff --git a/sysdeps/ieee754/flt-32/s_sinpif.c b/sysdeps/ieee754/flt-32/s_sinpif.c > new file mode 100644 > index 0000000000..772ea428e2 > --- /dev/null > +++ b/sysdeps/ieee754/flt-32/s_sinpif.c > @@ -0,0 +1,134 @@ > +/* Correctly-rounded sine of binary32 value for angles in half-revolutions > + > +Copyright (c) 2022-2025 Alexei Sibidanov. > + > +The original version of this file was copied from the CORE-MATH > +project (src/binary32/sinpi/sinpif.c, revision f786e13). > + > +Permission is hereby granted, free of charge, to any person obtaining a copy > +of this software and associated documentation files (the "Software"), to deal > +in the Software without restriction, including without limitation the rights > +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: > + > +The above copyright notice and this permission notice shall be included in all > +copies or substantial portions of the Software. > + > +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > +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. > +*/ > + > +#include <math.h> > +#include <stdint.h> > +#include <errno.h> > +#include <fenv.h> > +#include <libm-alias-float.h> > +#include "math_config.h" > + > +float > +__sinpif (float x) > +{ > + static const double sn[] = > + { > + 0x1.921fb54442d0fp-37, -0x1.4abbce6102b94p-112, 0x1.4669fa3c58463p-189 > + }; > + static const double cn[] = > + { > + -0x1.3bd3cc9be45cfp-74, 0x1.03c1f08088742p-150, -0x1.55d1e5eff55a5p-228 > + }; > + static const double S[] = > + { > + 0x0p+0, 0x1.91f65f10dd814p-5, 0x1.917a6bc29b42cp-4, > + 0x1.2c8106e8e613ap-3, 0x1.8f8b83c69a60bp-3, 0x1.f19f97b215f1bp-3, > + 0x1.294062ed59f06p-2, 0x1.58f9a75ab1fddp-2, 0x1.87de2a6aea963p-2, > + 0x1.b5d1009e15ccp-2, 0x1.e2b5d3806f63bp-2, 0x1.073879922ffeep-1, > + 0x1.1c73b39ae68c8p-1, 0x1.30ff7fce17035p-1, 0x1.44cf325091dd6p-1, > + 0x1.57d69348cecap-1, 0x1.6a09e667f3bcdp-1, 0x1.7b5df226aafafp-1, > + 0x1.8bc806b151741p-1, 0x1.9b3e047f38741p-1, 0x1.a9b66290ea1a3p-1, > + 0x1.b728345196e3ep-1, 0x1.c38b2f180bdb1p-1, 0x1.ced7af43cc773p-1, > + 0x1.d906bcf328d46p-1, 0x1.e212104f686e5p-1, 0x1.e9f4156c62ddap-1, > + 0x1.f0a7efb9230d7p-1, 0x1.f6297cff75cbp-1, 0x1.fa7557f08a517p-1, > + 0x1.fd88da3d12526p-1, 0x1.ff621e3796d7ep-1, 0x1p+0, > + 0x1.ff621e3796d7ep-1, 0x1.fd88da3d12526p-1, 0x1.fa7557f08a517p-1, > + 0x1.f6297cff75cbp-1, 0x1.f0a7efb9230d7p-1, 0x1.e9f4156c62ddap-1, > + 0x1.e212104f686e5p-1, 0x1.d906bcf328d46p-1, 0x1.ced7af43cc773p-1, > + 0x1.c38b2f180bdb1p-1, 0x1.b728345196e3ep-1, 0x1.a9b66290ea1a3p-1, > + 0x1.9b3e047f38741p-1, 0x1.8bc806b151741p-1, 0x1.7b5df226aafafp-1, > + 0x1.6a09e667f3bcdp-1, 0x1.57d69348cecap-1, 0x1.44cf325091dd6p-1, > + 0x1.30ff7fce17035p-1, 0x1.1c73b39ae68c8p-1, 0x1.073879922ffeep-1, > + 0x1.e2b5d3806f63bp-2, 0x1.b5d1009e15ccp-2, 0x1.87de2a6aea963p-2, > + 0x1.58f9a75ab1fddp-2, 0x1.294062ed59f06p-2, 0x1.f19f97b215f1bp-3, > + 0x1.8f8b83c69a60bp-3, 0x1.2c8106e8e613ap-3, 0x1.917a6bc29b42cp-4, > + 0x1.91f65f10dd814p-5, 0x0p+0, -0x1.91f65f10dd814p-5, > + -0x1.917a6bc29b42cp-4, -0x1.2c8106e8e613ap-3, -0x1.8f8b83c69a60bp-3, > + -0x1.f19f97b215f1bp-3, -0x1.294062ed59f06p-2, -0x1.58f9a75ab1fddp-2, > + -0x1.87de2a6aea963p-2, -0x1.b5d1009e15ccp-2, -0x1.e2b5d3806f63bp-2, > + -0x1.073879922ffeep-1, -0x1.1c73b39ae68c8p-1, -0x1.30ff7fce17035p-1, > + -0x1.44cf325091dd6p-1, -0x1.57d69348cecap-1, -0x1.6a09e667f3bcdp-1, > + -0x1.7b5df226aafafp-1, -0x1.8bc806b151741p-1, -0x1.9b3e047f38741p-1, > + -0x1.a9b66290ea1a3p-1, -0x1.b728345196e3ep-1, -0x1.c38b2f180bdb1p-1, > + -0x1.ced7af43cc773p-1, -0x1.d906bcf328d46p-1, -0x1.e212104f686e5p-1, > + -0x1.e9f4156c62ddap-1, -0x1.f0a7efb9230d7p-1, -0x1.f6297cff75cbp-1, > + -0x1.fa7557f08a517p-1, -0x1.fd88da3d12526p-1, -0x1.ff621e3796d7ep-1, > + -0x1p+0, -0x1.ff621e3796d7ep-1, -0x1.fd88da3d12526p-1, > + -0x1.fa7557f08a517p-1, -0x1.f6297cff75cbp-1, -0x1.f0a7efb9230d7p-1, > + -0x1.e9f4156c62ddap-1, -0x1.e212104f686e5p-1, -0x1.d906bcf328d46p-1, > + -0x1.ced7af43cc773p-1, -0x1.c38b2f180bdb1p-1, -0x1.b728345196e3ep-1, > + -0x1.a9b66290ea1a3p-1, -0x1.9b3e047f38741p-1, -0x1.8bc806b151741p-1, > + -0x1.7b5df226aafafp-1, -0x1.6a09e667f3bcdp-1, -0x1.57d69348cecap-1, > + -0x1.44cf325091dd6p-1, -0x1.30ff7fce17035p-1, -0x1.1c73b39ae68c8p-1, > + -0x1.073879922ffeep-1, -0x1.e2b5d3806f63bp-2, -0x1.b5d1009e15ccp-2, > + -0x1.87de2a6aea963p-2, -0x1.58f9a75ab1fddp-2, -0x1.294062ed59f06p-2, > + -0x1.f19f97b215f1bp-3, -0x1.8f8b83c69a60bp-3, -0x1.2c8106e8e613ap-3, > + -0x1.917a6bc29b42cp-4, -0x1.91f65f10dd814p-5 > + }; > + > + uint32_t ix = asuint (x); > + int32_t e = (ix >> 23) & 0xff; > + if (__glibc_unlikely (e == 0xff)) > + { > + if (!(ix << 9)) > + return __math_invalidf (x); > + return x + x; /* nan */ > + } > + int32_t m = (ix & ~0u >> 9) | 1 << 23, sgn = ix; > + sgn >>= 31; > + m = (m ^ sgn) - sgn; > + int32_t s = 143 - e; > + if (__glibc_unlikely (s < 0)) > + { > + if (__glibc_unlikely (s < -6)) > + return copysignf (0.0f, x); > + int32_t iq = m << (-s - 1); > + iq &= 127; > + if (iq == 0 || iq == 64) > + return copysignf (0.0f, x); > + return S[iq]; > + } > + else if (__glibc_unlikely (s > 30)) > + { > + double z = x, z2 = z * z; > + return z * (0x1.921fb54442d18p+1 + z2 * (-0x1.4abbce625be53p+2)); > + } > + int32_t si = 25 - s; > + if (__glibc_unlikely (si >= 0 && (m << si) == 0)) > + return copysignf (0.0f, x); > + > + int32_t k = m << (31 - s); > + double z = k, z2 = z * z; > + double fs = sn[0] + z2 * (sn[1] + z2 * sn[2]); > + double fc = cn[0] + z2 * (cn[1] + z2 * cn[2]); > + uint32_t iq = m >> s; > + iq = (iq + 1) >> 1; > + uint32_t is = iq & 127, ic = (iq + 32) & 127; > + double ts = S[is], tc = S[ic]; > + double r = ts + (ts * z2) * fc + (tc * z) * fs; > + return r; > +} > +libm_alias_float (__sinpi, sinpi) > diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps > index fe84c60913..4fadba43c2 100644 > --- a/sysdeps/loongarch/lp64/libm-test-ulps > +++ b/sysdeps/loongarch/lp64/libm-test-ulps > @@ -1389,22 +1389,18 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps > index ddc78d0239..5177b54557 100644 > --- a/sysdeps/mips/mips64/libm-test-ulps > +++ b/sysdeps/mips/mips64/libm-test-ulps > @@ -1402,22 +1402,18 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps > index 884b4cc361..1fb4ec57c0 100644 > --- a/sysdeps/or1k/fpu/libm-test-ulps > +++ b/sysdeps/or1k/fpu/libm-test-ulps > @@ -1082,19 +1082,15 @@ double: 3 > > Function: "sinpi": > double: 2 > -float: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > > Function: "sinpi_upward": > double: 2 > -float: 3 > > Function: "tan_downward": > double: 1 > diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps > index aec66e0fa3..aff11b5148 100644 > --- a/sysdeps/or1k/nofpu/libm-test-ulps > +++ b/sysdeps/or1k/nofpu/libm-test-ulps > @@ -991,7 +991,6 @@ double: 3 > > Function: "sinpi": > double: 2 > -float: 2 > > Function: "tan_downward": > double: 1 > diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps > index bdf0c98dc7..e59c3e47ef 100644 > --- a/sysdeps/powerpc/fpu/libm-test-ulps > +++ b/sysdeps/powerpc/fpu/libm-test-ulps > @@ -1779,25 +1779,21 @@ ldouble: 6 > > Function: "sinpi": > double: 2 > -float: 2 > float128: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > float128: 2 > ldouble: 5 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > float128: 2 > ldouble: 8 > > Function: "sinpi_upward": > double: 2 > -float: 3 > float128: 2 > ldouble: 8 > > diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps > index 08af2495f3..2545d0e166 100644 > --- a/sysdeps/riscv/nofpu/libm-test-ulps > +++ b/sysdeps/riscv/nofpu/libm-test-ulps > @@ -1271,7 +1271,6 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps > index 6644e38ebc..94534a4f80 100644 > --- a/sysdeps/riscv/rvd/libm-test-ulps > +++ b/sysdeps/riscv/rvd/libm-test-ulps > @@ -1401,22 +1401,18 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps > index 6318760eb5..2c89048b56 100644 > --- a/sysdeps/s390/fpu/libm-test-ulps > +++ b/sysdeps/s390/fpu/libm-test-ulps > @@ -1387,22 +1387,18 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps > index 2c319f8ae2..3af2355545 100644 > --- a/sysdeps/sparc/fpu/libm-test-ulps > +++ b/sysdeps/sparc/fpu/libm-test-ulps > @@ -1402,22 +1402,18 @@ ldouble: 4 > > Function: "sinpi": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > ldouble: 2 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > ldouble: 2 > > Function: "tan": > diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps > index e2cf3e04b6..f6da5ba186 100644 > --- a/sysdeps/x86_64/fpu/libm-test-ulps > +++ b/sysdeps/x86_64/fpu/libm-test-ulps > @@ -2197,25 +2197,21 @@ float: 1 > > Function: "sinpi": > double: 2 > -float: 2 > float128: 2 > ldouble: 2 > > Function: "sinpi_downward": > double: 2 > -float: 2 > float128: 2 > ldouble: 3 > > Function: "sinpi_towardzero": > double: 2 > -float: 1 > float128: 2 > ldouble: 2 > > Function: "sinpi_upward": > double: 2 > -float: 3 > float128: 2 > ldouble: 2 > > -- > 2.43.0 > >
diff --git a/SHARED-FILES b/SHARED-FILES index 3ce38d1542..c108f3b308 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -354,3 +354,7 @@ sysdeps/ieee754/flt-32/s_cospif.c: (src/binary32/cospi/cospif.c in CORE-MATH) - the code was adapted to use glibc code style and internal functions to handle errno, overflow, and underflow. +sysdeps/ieee754/flt-32/s_sinpif.c: + (src/binary32/sinpi/sinpif.c in CORE-MATH) + - the code was adapted to use glibc code style and internal + functions to handle errno, overflow, and underflow. diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps index a15f3effa0..c6c93aa0e4 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -1610,7 +1610,6 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "sinpi_advsimd": @@ -1619,7 +1618,6 @@ float: 2 Function: "sinpi_downward": double: 2 -float: 2 ldouble: 2 Function: "sinpi_sve": @@ -1628,12 +1626,10 @@ float: 2 Function: "sinpi_towardzero": double: 2 -float: 1 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 ldouble: 2 Function: "tan": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index f2acbf453e..65ebf6f9a0 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -1101,19 +1101,15 @@ double: 3 Function: "sinpi": double: 2 -float: 2 Function: "sinpi_downward": double: 2 -float: 2 Function: "sinpi_towardzero": double: 2 -float: 1 Function: "sinpi_upward": double: 2 -float: 3 Function: "tan": double: 1 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index 8716e5d29e..3ba4f01cbf 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -265,7 +265,6 @@ double: 2 Function: "sinpi": double: 2 -float: 2 Function: "tanh": double: 2 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index 647f92944c..f887712d8e 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -1097,19 +1097,15 @@ double: 3 Function: "sinpi": double: 2 -float: 2 Function: "sinpi_downward": double: 2 -float: 2 Function: "sinpi_towardzero": double: 2 -float: 1 Function: "sinpi_upward": double: 2 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 88f7701c0e..10f7f2ebde 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -1123,19 +1123,15 @@ double: 3 Function: "sinpi": double: 2 -float: 2 Function: "sinpi_downward": double: 2 -float: 2 Function: "sinpi_towardzero": double: 2 -float: 1 Function: "sinpi_upward": double: 2 -float: 3 Function: "tan": double: 1 diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index 39066956b0..77aa7155db 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -1691,25 +1691,21 @@ ldouble: 5 Function: "sinpi": double: 2 -float: 2 float128: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 float128: 2 ldouble: 2 Function: "sinpi_towardzero": double: 2 -float: 1 float128: 2 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 float128: 2 ldouble: 2 diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps index a8c4723850..7168d577d8 100644 --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps @@ -1696,25 +1696,21 @@ ldouble: 5 Function: "sinpi": double: 2 -float: 2 float128: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "sinpi_towardzero": double: 2 -float: 1 float128: 2 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 float128: 2 ldouble: 2 diff --git a/sysdeps/ieee754/flt-32/s_sinpif.c b/sysdeps/ieee754/flt-32/s_sinpif.c new file mode 100644 index 0000000000..772ea428e2 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_sinpif.c @@ -0,0 +1,134 @@ +/* Correctly-rounded sine of binary32 value for angles in half-revolutions + +Copyright (c) 2022-2025 Alexei Sibidanov. + +The original version of this file was copied from the CORE-MATH +project (src/binary32/sinpi/sinpif.c, revision f786e13). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +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. +*/ + +#include <math.h> +#include <stdint.h> +#include <errno.h> +#include <fenv.h> +#include <libm-alias-float.h> +#include "math_config.h" + +float +__sinpif (float x) +{ + static const double sn[] = + { + 0x1.921fb54442d0fp-37, -0x1.4abbce6102b94p-112, 0x1.4669fa3c58463p-189 + }; + static const double cn[] = + { + -0x1.3bd3cc9be45cfp-74, 0x1.03c1f08088742p-150, -0x1.55d1e5eff55a5p-228 + }; + static const double S[] = + { + 0x0p+0, 0x1.91f65f10dd814p-5, 0x1.917a6bc29b42cp-4, + 0x1.2c8106e8e613ap-3, 0x1.8f8b83c69a60bp-3, 0x1.f19f97b215f1bp-3, + 0x1.294062ed59f06p-2, 0x1.58f9a75ab1fddp-2, 0x1.87de2a6aea963p-2, + 0x1.b5d1009e15ccp-2, 0x1.e2b5d3806f63bp-2, 0x1.073879922ffeep-1, + 0x1.1c73b39ae68c8p-1, 0x1.30ff7fce17035p-1, 0x1.44cf325091dd6p-1, + 0x1.57d69348cecap-1, 0x1.6a09e667f3bcdp-1, 0x1.7b5df226aafafp-1, + 0x1.8bc806b151741p-1, 0x1.9b3e047f38741p-1, 0x1.a9b66290ea1a3p-1, + 0x1.b728345196e3ep-1, 0x1.c38b2f180bdb1p-1, 0x1.ced7af43cc773p-1, + 0x1.d906bcf328d46p-1, 0x1.e212104f686e5p-1, 0x1.e9f4156c62ddap-1, + 0x1.f0a7efb9230d7p-1, 0x1.f6297cff75cbp-1, 0x1.fa7557f08a517p-1, + 0x1.fd88da3d12526p-1, 0x1.ff621e3796d7ep-1, 0x1p+0, + 0x1.ff621e3796d7ep-1, 0x1.fd88da3d12526p-1, 0x1.fa7557f08a517p-1, + 0x1.f6297cff75cbp-1, 0x1.f0a7efb9230d7p-1, 0x1.e9f4156c62ddap-1, + 0x1.e212104f686e5p-1, 0x1.d906bcf328d46p-1, 0x1.ced7af43cc773p-1, + 0x1.c38b2f180bdb1p-1, 0x1.b728345196e3ep-1, 0x1.a9b66290ea1a3p-1, + 0x1.9b3e047f38741p-1, 0x1.8bc806b151741p-1, 0x1.7b5df226aafafp-1, + 0x1.6a09e667f3bcdp-1, 0x1.57d69348cecap-1, 0x1.44cf325091dd6p-1, + 0x1.30ff7fce17035p-1, 0x1.1c73b39ae68c8p-1, 0x1.073879922ffeep-1, + 0x1.e2b5d3806f63bp-2, 0x1.b5d1009e15ccp-2, 0x1.87de2a6aea963p-2, + 0x1.58f9a75ab1fddp-2, 0x1.294062ed59f06p-2, 0x1.f19f97b215f1bp-3, + 0x1.8f8b83c69a60bp-3, 0x1.2c8106e8e613ap-3, 0x1.917a6bc29b42cp-4, + 0x1.91f65f10dd814p-5, 0x0p+0, -0x1.91f65f10dd814p-5, + -0x1.917a6bc29b42cp-4, -0x1.2c8106e8e613ap-3, -0x1.8f8b83c69a60bp-3, + -0x1.f19f97b215f1bp-3, -0x1.294062ed59f06p-2, -0x1.58f9a75ab1fddp-2, + -0x1.87de2a6aea963p-2, -0x1.b5d1009e15ccp-2, -0x1.e2b5d3806f63bp-2, + -0x1.073879922ffeep-1, -0x1.1c73b39ae68c8p-1, -0x1.30ff7fce17035p-1, + -0x1.44cf325091dd6p-1, -0x1.57d69348cecap-1, -0x1.6a09e667f3bcdp-1, + -0x1.7b5df226aafafp-1, -0x1.8bc806b151741p-1, -0x1.9b3e047f38741p-1, + -0x1.a9b66290ea1a3p-1, -0x1.b728345196e3ep-1, -0x1.c38b2f180bdb1p-1, + -0x1.ced7af43cc773p-1, -0x1.d906bcf328d46p-1, -0x1.e212104f686e5p-1, + -0x1.e9f4156c62ddap-1, -0x1.f0a7efb9230d7p-1, -0x1.f6297cff75cbp-1, + -0x1.fa7557f08a517p-1, -0x1.fd88da3d12526p-1, -0x1.ff621e3796d7ep-1, + -0x1p+0, -0x1.ff621e3796d7ep-1, -0x1.fd88da3d12526p-1, + -0x1.fa7557f08a517p-1, -0x1.f6297cff75cbp-1, -0x1.f0a7efb9230d7p-1, + -0x1.e9f4156c62ddap-1, -0x1.e212104f686e5p-1, -0x1.d906bcf328d46p-1, + -0x1.ced7af43cc773p-1, -0x1.c38b2f180bdb1p-1, -0x1.b728345196e3ep-1, + -0x1.a9b66290ea1a3p-1, -0x1.9b3e047f38741p-1, -0x1.8bc806b151741p-1, + -0x1.7b5df226aafafp-1, -0x1.6a09e667f3bcdp-1, -0x1.57d69348cecap-1, + -0x1.44cf325091dd6p-1, -0x1.30ff7fce17035p-1, -0x1.1c73b39ae68c8p-1, + -0x1.073879922ffeep-1, -0x1.e2b5d3806f63bp-2, -0x1.b5d1009e15ccp-2, + -0x1.87de2a6aea963p-2, -0x1.58f9a75ab1fddp-2, -0x1.294062ed59f06p-2, + -0x1.f19f97b215f1bp-3, -0x1.8f8b83c69a60bp-3, -0x1.2c8106e8e613ap-3, + -0x1.917a6bc29b42cp-4, -0x1.91f65f10dd814p-5 + }; + + uint32_t ix = asuint (x); + int32_t e = (ix >> 23) & 0xff; + if (__glibc_unlikely (e == 0xff)) + { + if (!(ix << 9)) + return __math_invalidf (x); + return x + x; /* nan */ + } + int32_t m = (ix & ~0u >> 9) | 1 << 23, sgn = ix; + sgn >>= 31; + m = (m ^ sgn) - sgn; + int32_t s = 143 - e; + if (__glibc_unlikely (s < 0)) + { + if (__glibc_unlikely (s < -6)) + return copysignf (0.0f, x); + int32_t iq = m << (-s - 1); + iq &= 127; + if (iq == 0 || iq == 64) + return copysignf (0.0f, x); + return S[iq]; + } + else if (__glibc_unlikely (s > 30)) + { + double z = x, z2 = z * z; + return z * (0x1.921fb54442d18p+1 + z2 * (-0x1.4abbce625be53p+2)); + } + int32_t si = 25 - s; + if (__glibc_unlikely (si >= 0 && (m << si) == 0)) + return copysignf (0.0f, x); + + int32_t k = m << (31 - s); + double z = k, z2 = z * z; + double fs = sn[0] + z2 * (sn[1] + z2 * sn[2]); + double fc = cn[0] + z2 * (cn[1] + z2 * cn[2]); + uint32_t iq = m >> s; + iq = (iq + 1) >> 1; + uint32_t is = iq & 127, ic = (iq + 32) & 127; + double ts = S[is], tc = S[ic]; + double r = ts + (ts * z2) * fc + (tc * z) * fs; + return r; +} +libm_alias_float (__sinpi, sinpi) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index fe84c60913..4fadba43c2 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -1389,22 +1389,18 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 ldouble: 2 Function: "sinpi_towardzero": double: 2 -float: 1 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 ldouble: 2 Function: "tan": diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index ddc78d0239..5177b54557 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -1402,22 +1402,18 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 ldouble: 2 Function: "sinpi_towardzero": double: 2 -float: 1 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 ldouble: 2 Function: "tan": diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index 884b4cc361..1fb4ec57c0 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -1082,19 +1082,15 @@ double: 3 Function: "sinpi": double: 2 -float: 2 Function: "sinpi_downward": double: 2 -float: 2 Function: "sinpi_towardzero": double: 2 -float: 1 Function: "sinpi_upward": double: 2 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index aec66e0fa3..aff11b5148 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -991,7 +991,6 @@ double: 3 Function: "sinpi": double: 2 -float: 2 Function: "tan_downward": double: 1 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index bdf0c98dc7..e59c3e47ef 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -1779,25 +1779,21 @@ ldouble: 6 Function: "sinpi": double: 2 -float: 2 float128: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 float128: 2 ldouble: 5 Function: "sinpi_towardzero": double: 2 -float: 1 float128: 2 ldouble: 8 Function: "sinpi_upward": double: 2 -float: 3 float128: 2 ldouble: 8 diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 08af2495f3..2545d0e166 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -1271,7 +1271,6 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "tan": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index 6644e38ebc..94534a4f80 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -1401,22 +1401,18 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 ldouble: 2 Function: "sinpi_towardzero": double: 2 -float: 1 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 ldouble: 2 Function: "tan": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index 6318760eb5..2c89048b56 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -1387,22 +1387,18 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 ldouble: 2 Function: "sinpi_towardzero": double: 2 -float: 1 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 ldouble: 2 Function: "tan": diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 2c319f8ae2..3af2355545 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -1402,22 +1402,18 @@ ldouble: 4 Function: "sinpi": double: 2 -float: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 ldouble: 2 Function: "sinpi_towardzero": double: 2 -float: 1 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 ldouble: 2 Function: "tan": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index e2cf3e04b6..f6da5ba186 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -2197,25 +2197,21 @@ float: 1 Function: "sinpi": double: 2 -float: 2 float128: 2 ldouble: 2 Function: "sinpi_downward": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "sinpi_towardzero": double: 2 -float: 1 float128: 2 ldouble: 2 Function: "sinpi_upward": double: 2 -float: 3 float128: 2 ldouble: 2