[PATCH v2 00/11] math: Use CORE-MATH sin, cos, and sincos
Adhemerval Zanella
adhemerval.zanella@linaro.org
Wed Nov 18 18:15:12 GMT 2026
This series replaces the IBM binary64 sin, cos, and sincos with the
CORE-MATH implementations, which are correctly rounded in all rounding
modes.
- Patches 1-2 make roundeven_finite an architecture hook and add an
inline LoongArch version, used by the argument reductions.
- Patch 3 adds benchtests workloads for each code path (fast,
moderate, slow) of sincos, as sin and cos already have.
- Patch 4 moves the IBM cos to s_cos.c, so sin and cos can be
replaced separately.
- Patches 5-7 import sin and cos. Patch 6 makes j0, j1, y0,
and y1 compute their trigonometric terms in round-to-nearest, as
they relied on the IBM behavior (otherwise j1 and y1 exceed the
9 ulp threshold in the directed rounding modes).
- Patches 8-9 share the tables and routines: sin, cos, and their
ifunc variants use a single copy, and sincos is built on top of the
sin and cos code (with bitwise identical results).
- Patch 10 removes the x86_64 AVX variants of sin, cos, and sincos,
which no longer gain anything over the SSE2 ones.
- Patch 11 builds the sin and cos accurate paths once, in a separate
file shared by the x86_64 ifunc variants and by sincos.
Reciprocal throughput improvement in benchtests, on x86_64-v3 (Ryzen 9
5900X, gcc 16.1.1), aarch64 (Neoverse N1), power10 (POWER10), and
loongarch64 (Loongson-3C5000L-LL), the last three with gcc 16.2.1:
x86_64-v3 aarch64 power10 loongarch64
sin fast +30% -10% +172% -6%
moderate +37% +28% +236% +18%
slow 11.1x 7.1x 10.2x 6.3x
cos fast +38% +11% +202% +6%
moderate +47% +50% +250% +21%
slow 11.3x 7.0x 10.1x 6.3x
sincos fast -1% -28% +119% -3%
moderate +16% -1% +153% +18%
slow 8.6x 5.2x 7.8x 5.2x
The main regressions are sin and sincos on the aarch64 fast path (10%
and 28%). Without FMA (x86-64 baseline and v2), the software fma makes
sin, cos, and sincos 3.4x to 4.7x slower on the fast and moderate
paths.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Adhemerval Zanella (11):
math: Make roundeven_finite an architecture hook
loongarch: Add an inline roundeven_finite
benchtests: Add path-oriented workloads to sincos
math: Move the IBM cos implementation to s_cos.c
math: Use sin from CORE-MATH
math: Compute the j0, j1, y0, and y1 trigonometric terms in
round-to-nearest
math: Use cos from CORE-MATH
math: Consolidate the sin and cos tables and routines
math: Use sincos from CORE-MATH
x86_64: Remove the AVX variants of sin, cos, and sincos
math: Build the sin and cos accurate paths once
NEWS | 3 +-
SHARED-FILES | 6 +
benchtests/sincos-inputs | 8133 ++++++-----------
math/Makefile | 5 +-
math/auto-libm-test-in | 87 +
math/auto-libm-test-out-cos | 1286 +++
math/auto-libm-test-out-sin | 1587 ++++
math/auto-libm-test-out-sincos | 1555 ++++
sysdeps/generic/math-roundeven-finite.h | 45 +
sysdeps/generic/math_uint128.h | 14 +
sysdeps/i386/Makefile | 4 +
sysdeps/ieee754/dbl-64/e_j0.c | 17 +-
sysdeps/ieee754/dbl-64/e_j1.c | 15 +-
sysdeps/ieee754/dbl-64/libm-test-ulps | 36 +
sysdeps/ieee754/dbl-64/math_config.h | 27 +-
sysdeps/ieee754/dbl-64/s_cos.c | 154 +-
sysdeps/ieee754/dbl-64/s_sin.c | 433 +-
sysdeps/ieee754/dbl-64/s_sin_common.h | 129 +
sysdeps/ieee754/dbl-64/s_sincos.c | 272 +-
sysdeps/ieee754/dbl-64/s_sincos_accurate.c | 333 +
sysdeps/ieee754/dbl-64/s_sincos_data.c | 783 ++
sysdeps/ieee754/dbl-64/s_sincos_data.h | 62 +
sysdeps/ieee754/dbl-64/sincostab.c | 913 --
sysdeps/ieee754/dbl-64/usncs.h | 47 -
sysdeps/ieee754/flt-32/math_config.h | 52 +-
sysdeps/loongarch/fpu/math-roundeven-finite.h | 46 +
.../fpu/{sincostab.c => s_sincos_accurate.c} | 0
sysdeps/m68k/m680x0/fpu/s_sincos_data.c | 1 +
sysdeps/powerpc/fpu/math-roundeven-finite.h | 64 +
sysdeps/powerpc/fpu/math_private.h | 6 -
sysdeps/x86_64/fpu/multiarch/Makefile | 8 +-
sysdeps/x86_64/fpu/multiarch/s_cos-fma.c | 4 +
sysdeps/x86_64/fpu/multiarch/s_cos-fma4.c | 4 +
sysdeps/x86_64/fpu/multiarch/s_cos.c | 33 +
sysdeps/x86_64/fpu/multiarch/s_sin-avx.c | 5 -
sysdeps/x86_64/fpu/multiarch/s_sin-fma.c | 7 -
sysdeps/x86_64/fpu/multiarch/s_sin-fma4.c | 7 -
sysdeps/x86_64/fpu/multiarch/s_sin.c | 13 +-
sysdeps/x86_64/fpu/multiarch/s_sincos-avx.c | 3 -
39 files changed, 9590 insertions(+), 6609 deletions(-)
create mode 100644 sysdeps/generic/math-roundeven-finite.h
create mode 100644 sysdeps/ieee754/dbl-64/s_sin_common.h
create mode 100644 sysdeps/ieee754/dbl-64/s_sincos_accurate.c
create mode 100644 sysdeps/ieee754/dbl-64/s_sincos_data.c
create mode 100644 sysdeps/ieee754/dbl-64/s_sincos_data.h
delete mode 100644 sysdeps/ieee754/dbl-64/sincostab.c
delete mode 100644 sysdeps/ieee754/dbl-64/usncs.h
create mode 100644 sysdeps/loongarch/fpu/math-roundeven-finite.h
rename sysdeps/m68k/m680x0/fpu/{sincostab.c => s_sincos_accurate.c} (100%)
create mode 100644 sysdeps/m68k/m680x0/fpu/s_sincos_data.c
create mode 100644 sysdeps/powerpc/fpu/math-roundeven-finite.h
create mode 100644 sysdeps/x86_64/fpu/multiarch/s_cos-fma.c
create mode 100644 sysdeps/x86_64/fpu/multiarch/s_cos-fma4.c
create mode 100644 sysdeps/x86_64/fpu/multiarch/s_cos.c
delete mode 100644 sysdeps/x86_64/fpu/multiarch/s_sin-avx.c
delete mode 100644 sysdeps/x86_64/fpu/multiarch/s_sincos-avx.c
--
2.53.0
More information about the Libc-alpha
mailing list