This is an archive of the discontinued LLVM Phabricator instance.

[libc] Make expm1f correctly rounded when the targets have no FMA instructions.
ClosedPublic

Authored by lntue on Apr 8 2022, 9:08 PM.

Details

Summary

Add another exceptional value and fix the case when |x| is small.

Performance tests with CORE-MATH project scripts:
With FMA instructions on Ryzen 1700:

$ ./perf.sh expm1f
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH reciprocal throughput   : 15.362
System LIBC reciprocal throughput : 53.194
LIBC reciprocal throughput        : 14.595
$ ./perf.sh expm1f --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH latency   : 57.755
System LIBC latency : 147.020
LIBC latency        : 60.269

Without FMA instructions:

$ ./perf.sh expm1f
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH reciprocal throughput   : 15.362
System LIBC reciprocal throughput : 53.300
LIBC reciprocal throughput        : 18.020
$ ./perf.sh expm1f --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH latency   : 57.758
System LIBC latency : 147.025
LIBC latency        : 70.304

Diff Detail

Event Timeline

lntue created this revision.Apr 8 2022, 9:08 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 8 2022, 9:08 PM
lntue requested review of this revision.Apr 8 2022, 9:08 PM
lntue updated this revision to Diff 421683.Apr 8 2022, 9:17 PM

Fix unit tests.

lntue updated this revision to Diff 421940.Apr 11 2022, 8:59 AM

Add non-FMA unit tests for targets having FMA.

lntue updated this revision to Diff 421971.Apr 11 2022, 10:53 AM

Add exhaustive tests for non-FMA targets.

lntue edited the summary of this revision. (Show Details)Apr 11 2022, 10:57 AM
lntue edited the summary of this revision. (Show Details)
lntue updated this revision to Diff 425544.Apr 27 2022, 9:41 AM

Sync to HEAD.

This revision is now accepted and ready to land.Apr 27 2022, 9:59 AM
sivachandra added inline comments.Apr 27 2022, 5:26 PM
libc/src/math/generic/expm1f.cpp
44

Would making this unconditional to availability of fma affect the case when fma is available take a performance hit?

libc/test/src/math/exhaustive/expm1f_no_fma_test.cpp
11 ↗(On Diff #425544)

This is another of those situations where having configs avoids this ugliness. Lets give it some more thought so that we can solve this problem cleanly in a more general fashion. We should not need to add a separate expm1f_no_fma_test.cpp and a corresponding target. Just one expm1_test.cpp should be built and tested in two different contexts, one with fma, another without fma.

lntue updated this revision to Diff 427956.May 8 2022, 2:21 PM

Rely on https://reviews.llvm.org/D125174 and https://reviews.llvm.org/D123615
for testing with and without FMA flags.