This is an archive of the discontinued LLVM Phabricator instance.

[libc] Implement cosf function that is correctly rounded to all rounding modes.
ClosedPublic

Authored by lntue on Jul 27 2022, 9:25 AM.

Details

Summary

Implement cosf function that is correctly rounded to all rounding
modes.

Performance benchmark using perf tool from CORE-MATH project

(https://gitlab.inria.fr/core-math/core-math/-/tree/master) on Ryzen 1700:
Before this patch (not correctly rounded):

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf
CORE-MATH reciprocal throughput   : 19.043
System LIBC reciprocal throughput : 26.328
LIBC reciprocal throughput        : 30.955

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 49.995
System LIBC latency : 59.286
LIBC latency        : 60.174

After this patch (correctly rounded):

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 19.072
System LIBC reciprocal throughput : 26.286
LIBC reciprocal throughput        : 13.631

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 49.872
System LIBC latency : 59.468
LIBC latency        : 56.119

Diff Detail

Event Timeline

lntue created this revision.Jul 27 2022, 9:25 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 27 2022, 9:25 AM
lntue requested review of this revision.Jul 27 2022, 9:25 AM
lntue edited the summary of this revision. (Show Details)Jul 27 2022, 9:32 AM
orex accepted this revision.Jul 27 2022, 1:03 PM
orex added inline comments.
libc/test/src/math/exhaustive/cosf_test.cpp
58

Why the comments below?

This revision is now accepted and ready to land.Jul 27 2022, 1:03 PM
lntue updated this revision to Diff 448183.Jul 27 2022, 3:25 PM

Re-enable negative part of the exhaustive test.

libc/test/src/math/exhaustive/cosf_test.cpp
58

Oops, I disabled and forgot to re-enable it.

zimmermann6 accepted this revision.Jul 28 2022, 12:36 AM

this looks all good to me:

GNU libc version: 2.33
GNU libc release: release
17.271
25.064
13.555
GNU libc version: 2.33
GNU libc release: release
48.048
58.428
54.403

The first figures are for reciprocal throughput (core-math, glibc, llvm-libc), the second ones are for the latency. Great work!