This is an archive of the discontinued LLVM Phabricator instance.

[libc][math] Implement exp10f function correctly rounded to all rounding modes.
ClosedPublic

Authored by lntue on Sep 16 2022, 11:01 PM.

Details

Summary

Implement exp10f function correctly rounded to all rounding modes.

Algorithm: perform range reduction to reduce

10^x = 2^(hi + mid) * 10^lo

where:

hi is an integer,
0 <= mid * 2^5 < 2^5
-log10(2) / 2^6 <= lo <= log10(2) / 2^6

Then 2^mid is stored in a table of 32 entries and the product 2^hi * 2^mid is
performed by adding hi into the exponent field of 2^mid.
10^lo is then approximated by a degree-5 minimax polynomials generated by Sollya with:

> P = fpminimax((10^x - 1)/x, 4, [|D...|], [-log10(2)/64. log10(2)/64]);

Performance benchmark using perf tool from the CORE-MATH project on Ryzen 1700:

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp10f
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH reciprocal throughput   : 10.215
System LIBC reciprocal throughput : 7.944

LIBC reciprocal throughput        : 38.538
LIBC reciprocal throughput        : 12.175   (with `-msse4.2` flag)
LIBC reciprocal throughput        : 9.862    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp10f --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 40.744
System LIBC latency : 37.546

BEFORE
LIBC latency        : 48.989
LIBC latency        : 44.486   (with `-msse4.2` flag)
LIBC latency        : 40.221   (with `-mfma` flag)

This patch relies on https://reviews.llvm.org/D134002

Diff Detail

Event Timeline

lntue created this revision.Sep 16 2022, 11:01 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 16 2022, 11:01 PM
lntue requested review of this revision.Sep 16 2022, 11:01 PM
lntue edited the summary of this revision. (Show Details)Sep 16 2022, 11:15 PM
orex accepted this revision.Sep 17 2022, 9:18 AM
This revision is now accepted and ready to land.Sep 17 2022, 9:18 AM
zimmermann6 requested changes to this revision.Sep 19 2022, 1:23 AM

I got one reject when applying this patch to main (revision 458598c):

patching file libc/src/math/generic/explogxf.h
Hunk #1 FAILED at 51.
Hunk #2 succeeded at 41 with fuzz 2 (offset -29 lines).
1 out of 2 hunks FAILED -- saving rejects to file libc/src/math/generic/explogxf.h.rej
This revision now requires changes to proceed.Sep 19 2022, 1:23 AM
lntue updated this revision to Diff 461192.Sep 19 2022, 5:44 AM

Sync to head.

lntue added a comment.Sep 19 2022, 5:46 AM

I got one reject when applying this patch to main (revision 458598c):

patching file libc/src/math/generic/explogxf.h
Hunk #1 FAILED at 51.
Hunk #2 succeeded at 41 with fuzz 2 (offset -29 lines).
1 out of 2 hunks FAILED -- saving rejects to file libc/src/math/generic/explogxf.h.rej

I've committed https://reviews.llvm.org/D134002 and sync this patch. Can you check again if it's ok now? Thanks

lntue updated this revision to Diff 461196.Sep 19 2022, 6:31 AM

Sync to head.

zimmermann6 accepted this revision.Sep 19 2022, 6:49 AM

thank you, the new version is fine. Great work!

This revision is now accepted and ready to land.Sep 19 2022, 6:49 AM
This revision was landed with ongoing or failed builds.Sep 19 2022, 7:01 AM
This revision was automatically updated to reflect the committed changes.