This is an archive of the discontinued LLVM Phabricator instance.

[libc] Improve the performance of expf.
ClosedPublic

Authored by lntue on Mar 24 2022, 10:28 AM.

Details

Summary

Reduce the polynomial's degree from 7 down to 4.

Currently we use a degree-7 minimax polynomial on an interval of length 2^-7
around 0 to compute expf. Based on the suggestion of @santoshn and the RLIBM
project (https://github.com/rutgers-apl/rlibm-all/blob/main/source/float/exp.c)
and the improvement we made with exp2f in https://reviews.llvm.org/D122346,
it is possible to have a good polynomial of degree-4 on a subinterval of length
2^(-7) to approximate e^x.

We did try to either reduce the degree of the polynomial down to 3 or increase
the interval size to 2^(-6), but in both cases the number of exceptional values
exploded. So we settle with using a degree-4 polynomial of the interval of
size 2^(-7) around 0.

Diff Detail

Event Timeline

lntue created this revision.Mar 24 2022, 10:28 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 24 2022, 10:28 AM
lntue requested review of this revision.Mar 24 2022, 10:28 AM
lntue updated this revision to Diff 418070.Mar 24 2022, 4:11 PM

Update comments.

lntue edited the summary of this revision. (Show Details)Mar 24 2022, 4:18 PM
lntue added a subscriber: santoshn.
zimmermann6 accepted this revision.Mar 25 2022, 4:35 AM

ok for me, all exhaustive tests pass, and the performance increased a lot:

zimmerma@tomate:~/svn/core-math$ LIBM=/users/zimmerma/svn/core-math/libllvmlibc.a ./perf.sh expf
21.594
10.968
51.286
zimmerma@tomate:~/svn/core-math$ LIBM=/tmp/libllvmlibc.a ./perf.sh expf
21.596
10.966
16.997

The first run is with the previous version, the second one with the new version. The last timing is the one for llvm-libc, the first one for core-math, and the 2nd one for the GNU libc (not CR).

This revision is now accepted and ready to land.Mar 25 2022, 4:35 AM
santoshn accepted this revision.Mar 25 2022, 5:30 AM

Looks good to me.

sivachandra accepted this revision.Mar 25 2022, 8:40 AM
This revision was automatically updated to reflect the committed changes.