[PATCH v2 0/8] Add binary64 cosh/sinh/tanh CORE-MATH implementations to libm
Adhemerval Zanella
adhemerval.zanella@linaro.org
Fri Mar 6 12:25:17 GMT 2026
As for previous binary64 work, I prioritized functions with the lowest
accuracy. While binary32 allows exhaustive input accuracy checks using
CPU time, binary64 requires a combination of mathematical analysis and
statistical testing to ensure correctness.
For the former, Paul Zimmermann and others [1][2] work on the analysis
and requirements for the efficient and correctly rounded implementation
of elementary functions in floating-point arithmetic, as defined by the
additional mathematical operations of IEEE 754-2019.
For the latter, I compared the current and CORE-MATH implementations
across various input ranges using uniformly distributed random numbers
to assess accuracy and confirm CORE-MATH correctness.
This patch introduces CORE-MATH implementations for cosh, sinh, and tanh,
which exhibited lower accuracy, particularly in non-default rounding modes.
As before, the CORE-MATH code was adapted to match glibc code style and
internal math definitions. I also separated data and common definitions
to prevent data definitions from being built in ifunc on x86_64 and to
support code maintainability.
Performance results are mixed, depending on whether the ISA supports a
fast FMA operation: cosh shows some regressions, while both sinh and tanh
show improvements. This is mitigated on x86_64 with a new cosh ifunc
variant and a fix for tanh.
[1] https://inria.hal.science/hal-04474530
[2] https://members.loria.fr/PZimmermann/papers/accuracy.pdf
Changes from v2:
- Sync with CORE-MATH commit 2d845342553a4283a64a930b67c6c7ccb6421faf,
which fixes corner cases for cosh and sinh.
Adhemerval Zanella (8):
math: Use cosh from CORE-MATH
math: Remove the SVID error handling from cosh
math: Use sinh from CORE-MATH
math: Remove the SVID error handling from sinh
math: Use tanh from CORE-MATH
math: Consolidated common definition/data for cosh/sinh/tanh
x86_64: Add cosh with FMA
x86: Fix tanh ifunc selection
NEWS | 7 +-
SHARED-FILES | 6 +
math/Makefile | 4 +
math/Versions | 5 +
math/auto-libm-test-in | 55 +
math/auto-libm-test-out-cosh | 897 ++++++
math/auto-libm-test-out-sinh | 2760 +++++++++++++++++
math/auto-libm-test-out-tanh | 69 +
math/w_cosh_compat.c | 18 +-
math/w_sinh_compat.c | 18 +-
sysdeps/i386/Makefile | 3 +
sysdeps/i386/fpu/libm-test-ulps | 10 +
sysdeps/ieee754/dbl-64/e_cosh.c | 360 ++-
sysdeps/ieee754/dbl-64/e_cosh_data.c | 60 +
sysdeps/ieee754/dbl-64/e_cosh_data.h | 38 +
sysdeps/ieee754/dbl-64/e_coshsinh_data.c | 168 +
sysdeps/ieee754/dbl-64/e_coshsinh_data.h | 35 +
sysdeps/ieee754/dbl-64/e_sinh.c | 362 ++-
sysdeps/ieee754/dbl-64/e_sinh_data.c | 86 +
sysdeps/ieee754/dbl-64/e_sinh_data.h | 35 +
sysdeps/ieee754/dbl-64/e_tanh_data.c | 59 +
sysdeps/ieee754/dbl-64/e_tanh_data.h | 38 +
sysdeps/ieee754/dbl-64/libm-test-ulps | 36 +
sysdeps/ieee754/dbl-64/math_config.h | 3 +
sysdeps/ieee754/dbl-64/math_err.c | 2 +-
sysdeps/ieee754/dbl-64/s_tanh.c | 319 +-
sysdeps/ieee754/dbl-64/w_cosh.c | 1 +
sysdeps/ieee754/dbl-64/w_sinh.c | 1 +
sysdeps/m68k/m680x0/fpu/w_cosh_compat.c | 8 +
sysdeps/m68k/m680x0/fpu/w_sinh_compat.c | 8 +
sysdeps/mach/hurd/i386/libm.abilist | 2 +
sysdeps/unix/sysv/linux/aarch64/libm.abilist | 2 +
sysdeps/unix/sysv/linux/alpha/libm.abilist | 2 +
sysdeps/unix/sysv/linux/arm/be/libm.abilist | 2 +
sysdeps/unix/sysv/linux/arm/le/libm.abilist | 2 +
sysdeps/unix/sysv/linux/hppa/libm.abilist | 2 +
sysdeps/unix/sysv/linux/i386/libm.abilist | 2 +
.../sysv/linux/m68k/coldfire/libm.abilist | 2 +
.../sysv/linux/microblaze/be/libm.abilist | 2 +
.../sysv/linux/microblaze/le/libm.abilist | 2 +
.../unix/sysv/linux/mips/mips32/libm.abilist | 2 +
.../unix/sysv/linux/mips/mips64/libm.abilist | 2 +
.../linux/powerpc/powerpc32/fpu/libm.abilist | 2 +
.../powerpc/powerpc32/nofpu/libm.abilist | 2 +
.../linux/powerpc/powerpc64/be/libm.abilist | 2 +
.../linux/powerpc/powerpc64/le/libm.abilist | 2 +
.../unix/sysv/linux/s390/s390-32/libm.abilist | 2 +
.../unix/sysv/linux/s390/s390-64/libm.abilist | 2 +
sysdeps/unix/sysv/linux/sh/be/libm.abilist | 2 +
sysdeps/unix/sysv/linux/sh/le/libm.abilist | 2 +
.../sysv/linux/sparc/sparc32/libm.abilist | 2 +
.../sysv/linux/sparc/sparc64/libm.abilist | 2 +
.../unix/sysv/linux/x86_64/64/libm.abilist | 2 +
.../unix/sysv/linux/x86_64/x32/libm.abilist | 2 +
sysdeps/x86_64/fpu/multiarch/Makefile | 2 +
sysdeps/x86_64/fpu/multiarch/e_cosh-fma.c | 5 +
sysdeps/x86_64/fpu/multiarch/e_cosh.c | 44 +
sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c | 9 +-
sysdeps/x86_64/fpu/multiarch/e_sinh.c | 17 +-
sysdeps/x86_64/fpu/multiarch/s_tanh.c | 5 +-
60 files changed, 5343 insertions(+), 258 deletions(-)
create mode 100644 sysdeps/ieee754/dbl-64/e_cosh_data.c
create mode 100644 sysdeps/ieee754/dbl-64/e_cosh_data.h
create mode 100644 sysdeps/ieee754/dbl-64/e_coshsinh_data.c
create mode 100644 sysdeps/ieee754/dbl-64/e_coshsinh_data.h
create mode 100644 sysdeps/ieee754/dbl-64/e_sinh_data.c
create mode 100644 sysdeps/ieee754/dbl-64/e_sinh_data.h
create mode 100644 sysdeps/ieee754/dbl-64/e_tanh_data.c
create mode 100644 sysdeps/ieee754/dbl-64/e_tanh_data.h
create mode 100644 sysdeps/ieee754/dbl-64/w_cosh.c
create mode 100644 sysdeps/ieee754/dbl-64/w_sinh.c
create mode 100644 sysdeps/m68k/m680x0/fpu/w_cosh_compat.c
create mode 100644 sysdeps/m68k/m680x0/fpu/w_sinh_compat.c
create mode 100644 sysdeps/x86_64/fpu/multiarch/e_cosh-fma.c
create mode 100644 sysdeps/x86_64/fpu/multiarch/e_cosh.c
--
2.43.0
More information about the Libc-alpha
mailing list