[PATCH 00/13] math: Use CORE-MATH sin, cos, tan, and sincos
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Nov 17 20:46:38 GMT 2026
This series replaces the IBM binary64 sin, cos, tan, 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.
- Patches 3-4 add benchtests workloads for each code path (fast,
moderate, slow) of sincos and tan, as sin and cos already have.
- Patch 5 moves the IBM cos to s_cos.c, so sin and cos can be
replaced separately.
- Patches 6-9 import sin, cos, and tan. Patch 7 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 10-12 share the tables and routines: sin, cos, and their
ifunc variants use a single copy, sincos is built on top of the sin
and cos code (with bitwise identical results), and the tan tables
move to the same file.
- Patch 13 removes the x86_64 AVX variants, which no longer gain
anything over the SSE2 ones.
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 +28% -13% +171% -5%
moderate +38% +23% +249% +19%
slow 11.2x 6.9x 9.7x 6.3x
cos fast +40% +4% +200% +10%
moderate +46% +37% +256% +22%
slow 11.5x 6.9x 9.9x 6.4x
tan fast -42% -48% +45% -38%
moderate -38% -42% +28% -32%
slow 5.3x 3.2x 4.1x 3.0x
sincos fast -1% -29% +130% -4%
moderate +18% -3% +163% +18%
slow 8.6x 5.1x 7.5x 5.2x
The main regressions are tan on the fast and moderate paths, except on
power10, and sincos on the aarch64 fast path. Without FMA (x86-64
baseline and v2), the software fma makes sin and cos about 4x slower
and tan about 27x slower on these paths.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Adhemerval Zanella (13):
math: Make roundeven_finite an architecture hook
loongarch: Add an inline roundeven_finite
benchtests: Add path-oriented workloads to sincos
benchtests: Add a moderate workload to tan
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: Use tan from CORE-MATH
math: Consolidate the sin and cos tables and routines
math: Use sincos from CORE-MATH
math: Move the tan tables to s_sincos_data.c
x86_64: Remove the AVX variants of sin, cos, tan, and sincos
NEWS | 3 +-
SHARED-FILES | 8 +
benchtests/sincos-inputs | 8133 ++++++-----------
benchtests/tan-inputs | 1002 ++
math/Makefile | 5 +-
math/auto-libm-test-in | 117 +
math/auto-libm-test-out-cos | 1286 +++
math/auto-libm-test-out-sin | 1587 ++++
math/auto-libm-test-out-sincos | 1555 ++++
math/auto-libm-test-out-tan | 1654 ++++
sysdeps/generic/math-roundeven-finite.h | 45 +
sysdeps/generic/math_uint128.h | 14 +
sysdeps/i386/Makefile | 4 +
sysdeps/i386/fpu/libm-test-ulps | 5 +
sysdeps/ieee754/dbl-64/e_j0.c | 17 +-
sysdeps/ieee754/dbl-64/e_j1.c | 15 +-
sysdeps/ieee754/dbl-64/e_rem_pio2.c | 76 -
sysdeps/ieee754/dbl-64/libm-test-ulps | 48 +
sysdeps/ieee754/dbl-64/math_config.h | 27 +-
sysdeps/ieee754/dbl-64/s_cos.c | 223 +-
sysdeps/ieee754/dbl-64/s_sin.c | 494 +-
sysdeps/ieee754/dbl-64/s_sin_common.h | 285 +
sysdeps/ieee754/dbl-64/s_sincos.c | 367 +-
sysdeps/ieee754/dbl-64/s_sincos_data.c | 1694 ++++
sysdeps/ieee754/dbl-64/s_sincos_data.h | 72 +
sysdeps/ieee754/dbl-64/s_tan.c | 1804 +++-
sysdeps/ieee754/dbl-64/sincostab.c | 913 --
sysdeps/ieee754/dbl-64/usncs.h | 47 -
sysdeps/ieee754/dbl-64/utan.h | 96 -
sysdeps/ieee754/dbl-64/utan.tbl | 1524 ---
sysdeps/ieee754/flt-32/math_config.h | 52 +-
sysdeps/loongarch/fpu/math-roundeven-finite.h | 46 +
sysdeps/m68k/m680x0/fpu/e_rem_pio2.c | 1 -
.../fpu/{sincostab.c => s_sincos_data.c} | 0
sysdeps/powerpc/fpu/math-roundeven-finite.h | 60 +
sysdeps/powerpc/fpu/math_private.h | 6 -
sysdeps/x86_64/fpu/multiarch/Makefile | 10 +-
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 -
sysdeps/x86_64/fpu/multiarch/s_tan-avx.c | 6 -
sysdeps/x86_64/fpu/multiarch/s_tan-fma.c | 4 -
sysdeps/x86_64/fpu/multiarch/s_tan-fma4.c | 4 -
sysdeps/x86_64/fpu/multiarch/s_tan.c | 2 +-
49 files changed, 14706 insertions(+), 8681 deletions(-)
create mode 100644 sysdeps/generic/math-roundeven-finite.h
delete mode 100644 sysdeps/ieee754/dbl-64/e_rem_pio2.c
create mode 100644 sysdeps/ieee754/dbl-64/s_sin_common.h
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
delete mode 100644 sysdeps/ieee754/dbl-64/utan.h
delete mode 100644 sysdeps/ieee754/dbl-64/utan.tbl
create mode 100644 sysdeps/loongarch/fpu/math-roundeven-finite.h
delete mode 100644 sysdeps/m68k/m680x0/fpu/e_rem_pio2.c
rename sysdeps/m68k/m680x0/fpu/{sincostab.c => s_sincos_data.c} (100%)
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
delete mode 100644 sysdeps/x86_64/fpu/multiarch/s_tan-avx.c
--
2.53.0
More information about the Libc-alpha
mailing list