[PATCH v3 00/12] Add sinf/cosf/sincosf CORE-MATH implementations
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu Nov 19 18:43:04 GMT 2026
Ping.
On 23/09/26 18:50, Adhemerval Zanella wrote:
> This patchset adds the optimized and correctly rounded cosf, sinf, and
> sincosf from CORE-MATH [1]. The benchtests inputs are replaced by
> workloads aligned to the argument-reduction paths of the new code and
> to the SPEC CPU2017 fprate traces.
>
> Tracing every sin/cos/sincos call of the SPEC CPU2017 fprate benchmarks
> (ref inputs, one copy, inputs recorded through an LD_PRELOAD wrapper)
> shows where the argument actually lands. Share of calls per benchmark
> and function, using the argument-reduction bounds of the CORE-MATH
> implementation (fast: |x| < 3*pi (sinf/sincosf) or < 0x1.a41896p+3
> (cosf); moderate: up to 2^26; large: |x| >= 2^26):
>
> benchmark func calls |x| range fast moderate large
> 526.blender_r sincos 183.2M [-4.8, 6.28] 100% 0% 0%
> 526.blender_r sin 0.5M [-64, 46] 21% 79% 0%
> 511.povray_r sin 21.0M [0, 6.28] 100% 0% 0%
> 554.roms_r sincos 20.2M [-1.22, 0] 100% 0% 0%
> 554.roms_r cos 20.1M [-2.73, 3.14] 100% 0% 0%
> 508.namd_r cos 18.0M [65535, 1.8e7] 0% 100% 0%
> 544.nab_r sin 8.6M [0.015, 3.14] 100% 0% 0%
> 527.cam4_r sincos 4.5M [-1.57, 12.3] 95% 2% 0%
> 527.cam4_r sin 2.4M [-14.9, 14.9] 60% 39% 0%
> 527.cam4_r cos 2.4M [-4.9, 515] 20% 80% 0%
> 507.cactuBSSN_r sincos 0.6M [-103, 53] 18% 81% 0%
>
> The CORE-MATH implementation is correctly rounded in all rounding modes
> (the float sin, cos, and sincos ulps entries become 0). The results of
> sinf, cosf, sincosf, and tanf were compared exhaustively (all binary32
> inputs, four rounding modes) against MPFR on x86_64 (both ifunc
> variants), aarch64, loongarch, and powerpc64.
>
> The geomean of the reciprocal-throughput and latency over the random,
> moderate, and blender workloads against master, negative is faster
> (gcc 16.2.1, --enable-stack-protector=strong; x86_64 is a Ryzen 9
> 5900X with the FMA ifunc variant selected, aarch64 a Neoverse-N1,
> power10 a POWER10 built with -mcpu=power8, loongarch a
> Loongson-3C5000L-LL):
>
> sinf cosf sincosf
> x86_64 -8.2% -14.9% -19.0%
> x86_64v2 -10.3% -14.1% -19.4%
> x86_64v3 -9.9% -16.0% -18.8%
> aarch64 -12.2% -19.7% +1.4%
> power10 -15.7% -24.5% -14.7%
> loongarch -11.1% -15.9% -3.0%
>
> Changes from v2:
> - Benchtests workloads redefined from the SPEC CPU2017 traces
> (random, moderate, huge, and a 526.blender_r trace), replacing the
> random/large/huge ranges.
> - New patch evaluating the sincosf sine and cosine as two-lane
> vectors, with a single table shared by sinf, cosf, and sincosf.
> - Benchmarks re-run on the new workloads.
>
> Changes from v1:
> - Benchtests workloads redefined from the SPEC CPU2017 traces.
> - cosf synced with upstream (tiny-case optimization), citations and
> SHARED-FILES fixed.
> - roundeven_finite is an architecture hook (powerpc alternative moved
> to sysdeps/powerpc, inline loongarch implementation).
> - New patches shortening the fast path and evaluating the sincosf
> sine and cosine as two-lane vectors.
> - Benchmarks re-run with gcc 16.2.1 on x86_64, aarch64, power10, and
> loongarch.
>
> [1] https://gitlab.inria.fr/core-math/core-math
>
> Adhemerval Zanella (12):
> benchtests: Redefine cosf workloads
> benchtests: Redefine sinf workloads
> benchtests: Redefine sincosf workloads
> math: Make roundeven_finite an architecture hook
> loongarch: Add an inline roundeven_finite
> math: Use sinf from CORE-MATH
> math: Use cosf from CORE-MATH
> math: Use sincosf from CORE-MATH
> math: Consolidate common definitions for cosf/sinf/tanf/sincosf
> math: Remove unused definitions for sinf/cosf/sincosf implementation
> math: Shorten the sinf/cosf/sincosf fast path
> math: Evaluate the sincosf sine and cosine as two-lane vectors
>
> SHARED-FILES | 17 +-
> benchtests/cosf-inputs | 5412 +++++-----
> benchtests/sincosf-inputs | 9316 +++++++----------
> benchtests/sinf-inputs | 8926 +++++++---------
> math/Makefile | 2 +
> math/auto-libm-test-in | 1 +
> math/auto-libm-test-out-sincos | 25 +
> sysdeps/generic/math-roundeven-finite.h | 40 +
> sysdeps/ieee754/dbl-64/math_config.h | 27 +-
> sysdeps/ieee754/flt-32/libm-test-ulps | 36 +
> sysdeps/ieee754/flt-32/math_config.h | 52 +-
> sysdeps/ieee754/flt-32/reduce_aux.h | 38 +-
> .../flt-32/reduce_aux_data.c} | 37 +-
> sysdeps/ieee754/flt-32/s_cosf.c | 157 +-
> sysdeps/ieee754/flt-32/s_sincosf.c | 201 +-
> sysdeps/ieee754/flt-32/s_sincosf.h | 95 -
> sysdeps/ieee754/flt-32/s_sincosf_common.c | 91 +
> sysdeps/ieee754/flt-32/s_sincosf_common.h | 63 +
> sysdeps/ieee754/flt-32/s_sincosf_data.c | 167 +-
> sysdeps/ieee754/flt-32/s_sincosf_data.h | 70 +
> sysdeps/ieee754/flt-32/s_sinf.c | 166 +-
> sysdeps/ieee754/flt-32/s_tanf.c | 65 +-
> sysdeps/ieee754/flt-32/sincosf_poly.h | 87 -
> sysdeps/loongarch/fpu/math-roundeven-finite.h | 44 +
> sysdeps/powerpc/fpu/math-roundeven-finite.h | 60 +
> sysdeps/powerpc/fpu/math_private.h | 6 -
> sysdeps/x86/fpu/sincosf_poly.h | 111 -
> 27 files changed, 11946 insertions(+), 13366 deletions(-)
> create mode 100644 sysdeps/generic/math-roundeven-finite.h
> rename sysdeps/{x86/fpu/s_sincosf_data.c => ieee754/flt-32/reduce_aux_data.c} (58%)
> delete mode 100644 sysdeps/ieee754/flt-32/s_sincosf.h
> create mode 100644 sysdeps/ieee754/flt-32/s_sincosf_common.c
> create mode 100644 sysdeps/ieee754/flt-32/s_sincosf_common.h
> create mode 100644 sysdeps/ieee754/flt-32/s_sincosf_data.h
> delete mode 100644 sysdeps/ieee754/flt-32/sincosf_poly.h
> create mode 100644 sysdeps/loongarch/fpu/math-roundeven-finite.h
> create mode 100644 sysdeps/powerpc/fpu/math-roundeven-finite.h
> delete mode 100644 sysdeps/x86/fpu/sincosf_poly.h
>
More information about the Libc-alpha
mailing list