This is an archive of the discontinued LLVM Phabricator instance.

[libc] Use nearest_integer instructions to improve expf performance.
ClosedPublic

Authored by lntue on Jul 25 2022, 9:26 AM.

Details

Summary

Use nearest_integer instructions to improve expf performance.

Performance tests with CORE-MATH's perf tool:

Before the patch:

$ ./perf.sh expf
LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 9.860
System LIBC reciprocal throughput : 7.728
LIBC reciprocal throughput        : 12.363

$ ./perf.sh expf --latency
LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 42.802
System LIBC latency : 35.941
LIBC latency        : 49.808

After the patch:

$ ./perf.sh expf
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 9.441
System LIBC reciprocal throughput : 7.382
LIBC reciprocal throughput        : 8.843

$ ./perf.sh expf --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 44.192
System LIBC latency : 37.693
LIBC latency        : 44.145

Diff Detail

Event Timeline

lntue created this revision.Jul 25 2022, 9:26 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 25 2022, 9:26 AM
lntue requested review of this revision.Jul 25 2022, 9:26 AM
lntue updated this revision to Diff 447373.

Update math status page.

lntue edited the summary of this revision. (Show Details)Jul 25 2022, 9:30 AM
michaelrj added inline comments.Jul 25 2022, 10:47 AM
libc/src/math/generic/CMakeLists.txt
486

you should probably also explicitly include multiply add

lntue updated this revision to Diff 447412.Jul 25 2022, 11:14 AM

Add multiply_add to dependency.

lntue marked an inline comment as done.Jul 25 2022, 11:14 AM
zimmermann6 accepted this revision.Jul 26 2022, 1:09 AM

I confirm it is still correctly rounded, and now faster than CORE-MATH. Nice work!

This revision is now accepted and ready to land.Jul 26 2022, 1:09 AM