This is an archive of the discontinued LLVM Phabricator instance.

[libc] Improve the performance of exp2f.
ClosedPublic

Authored by lntue on Mar 23 2022, 12:47 PM.

Details

Summary

Reduce the range-reduction table size from 128 entries down to 64 entries, and
reduce the polynomial's degree from 6 down to 4.

Currently we use a degree-6 minimax polynomial on an interval of length 2^-7
around 0 to compute exp2f. Based on the suggestion of @santoshn and the RLIBM
project (https://github.com/rutgers-apl/rlibm-prog/blob/main/libm/float/exp2.c)
it is possible to have a good polynomial of degree-4 on a subinterval of length
2^(-6) to approximate 2^x.

We did try to either reduce the degree of the polynomial down to 3 or increase
the interval size to 2^(-5), 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^(-6) around 0.

Diff Detail

Event Timeline

lntue created this revision.Mar 23 2022, 12:47 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 23 2022, 12:47 PM
lntue requested review of this revision.Mar 23 2022, 12:47 PM
michaelrj accepted this revision.Mar 23 2022, 12:52 PM

LGTM from a code perspective

This revision is now accepted and ready to land.Mar 23 2022, 12:52 PM
lntue edited the summary of this revision. (Show Details)Mar 23 2022, 1:02 PM
lntue edited the summary of this revision. (Show Details)Mar 23 2022, 1:19 PM
sivachandra accepted this revision.Mar 23 2022, 1:24 PM

Fine with structuring but please curtail the CL description to 80 character width wherever possible.

lntue added a comment.Mar 23 2022, 1:31 PM

Fine with structuring but please curtail the CL description to 80 character width wherever possible.

The commit's message is the same as the title of the review patch, which is under 80 char. I just added more info about the patch to the summary part which should not be carried to the commit message.

Depending on how you submit, you might end up with this message in the git log. I do not know exactly what arc land will do or if you plan to use it to submit, but it could pick up the message from here when submitting.

lntue edited the summary of this revision. (Show Details)Mar 23 2022, 3:10 PM
lntue added a comment.Mar 23 2022, 4:20 PM

Depending on how you submit, you might end up with this message in the git log. I do not know exactly what arc land will do or if you plan to use it to submit, but it could pick up the message from here when submitting.

You are right, arc land does copy the summary from phabricators to commit messages. I updated the summary to stick with 80-char-width.

zimmermann6 accepted this revision.Mar 24 2022, 2:39 AM

I confirm the results are still correctly rounded for all four rounding modes. For rounding to nearest the reciprocal throughput/latency decreased from 56/103.5 cycles to 26.6/76.0 cycles on a Core i5-4590.
As a comparison, the core-math code runs in 21.2/63.2 cycles.

Looks good to me. Thanks for incorporating RLIBM style range reduction for exp2f. A degree-4 polynomial is impressive.

santoshn accepted this revision.Mar 24 2022, 8:52 AM
This revision was automatically updated to reflect the committed changes.