This is an archive of the discontinued LLVM Phabricator instance.

[libc][math] Simplify tanf implementation and improve its performance.
ClosedPublic

Authored by lntue on Sep 23 2022, 4:42 PM.

Details

Summary

Simplify tanf implementation and improve its performance.

Completely reuse the implementation of sinf, cosf, sincosf and use
the definition tan(x) = sin(x)/cos(x).

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

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH reciprocal throughput   : 18.558
System LIBC reciprocal throughput : 49.919

BEFORE:
LIBC reciprocal throughput        : 36.480
LIBC reciprocal throughput        : 27.217    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 20.205    (with `-mfma` flag)

AFTER:
LIBC reciprocal throughput        : 30.337
LIBC reciprocal throughput        : 21.072    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 15.804    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 56.702
System LIBC latency : 107.206

BEFORE
LIBC latency        : 97.598
LIBC latency        : 91.119   (with `-msse4.2` flag)
LIBC latency        : 82.655    (with `-mfma` flag)

AFTER
LIBC latency        : 74.560
LIBC latency        : 66.575    (with `-msse4.2` flag)
LIBC latency        : 61.636    (with `-mfma` flag)

Diff Detail

Event Timeline

lntue created this revision.Sep 23 2022, 4:42 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 23 2022, 4:42 PM
lntue requested review of this revision.Sep 23 2022, 4:42 PM
lntue edited the summary of this revision. (Show Details)Sep 23 2022, 4:48 PM
lntue updated this revision to Diff 462620.Sep 23 2022, 4:50 PM

Update performance table.

zimmermann6 accepted this revision.Sep 26 2022, 10:36 AM

I get similar timings:

zimmerma@biscotte:~/svn/core-math$ LIBM=/localdisk/zimmerma/llvm-project/build/projects/libc/lib/libllvmlibc.a CORE_MATH_PERF_MODE=rdtsc ./perf.sh tanf
GNU libc version: 2.34
GNU libc release: stable
14.464
50.813
14.254
zimmerma@biscotte:~/svn/core-math$ PERF_ARGS=--latency LIBM=/localdisk/zimmerma/llvm-project/build/projects/libc/lib/libllvmlibc.a CORE_MATH_PERF_MODE=rdtsc ./perf.sh tanf
GNU libc version: 2.34
GNU libc release: stable
54.500
110.220
59.640

Good work!

This revision is now accepted and ready to land.Sep 26 2022, 10:36 AM