This is an archive of the discontinued LLVM Phabricator instance.

[libc] Improve the performance of expf.

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



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 (
and the improvement we made with exp2f in,
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 ./ expf
zimmerma@tomate:~/svn/core-math$ LIBM=/tmp/libllvmlibc.a ./ expf

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.