This is an archive of the discontinued LLVM Phabricator instance.

[libc][math] Added sinhf function.
ClosedPublic

Authored by orex on Jul 7 2022, 4:49 AM.

Details

Summary

Latest performance.

CORE_MATH_PERF_MODE=rdtsc PERF_ARGS='' ./perf.sh sinhf
GNU libc version: 2.31
GNU libc release: stable
17.897
38.125
13.712
CORE_MATH_PERF_MODE=rdtsc PERF_ARGS='--latency' ./perf.sh sinhf
GNU libc version: 2.31
GNU libc release: stable
48.845
113.762
51.198

Diff Detail

Event Timeline

orex created this revision.Jul 7 2022, 4:49 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 7 2022, 4:49 AM
orex requested review of this revision.Jul 7 2022, 4:49 AM

should I apply this patch also on top of revision 60d6be5 + D129005 + D129215 ?

orex added a comment.Jul 12 2022, 6:46 AM

The easiest way, from my point of view, will be to apply it on top of working coshf branch, which you made and test.

The easiest way, from my point of view, will be to apply it on top of working coshf branch, which you made and test.

thank you, this worked perfectly. All exhaustive tests do pass, and the timings are as follows (same processor and compilers as D129275):

zimmerma@biscotte:~/svn/core-math$ LIBM=/localdisk/zimmerma/llvm-project/build/projects/libc/lib/libllvmlibc.a CORE_MATH_LAUNCHER="/localdisk/zimmerma/glibc-2.35/install/lib/ld-linux-x86-64.so.2 --library-path /localdisk/zimmerma/glibc-2.35/install/lib" CORE_MATH_PERF_MODE=rdtsc ./perf.sh sinhf
GNU libc version: 2.35
GNU libc release: stable
17.417
50.935
32.774

thus 17 cycles for CORE-MATH, 51 cycles for glibc 2.35, and 33 cycles for llvm-libc.

lntue added inline comments.Jul 19 2022, 9:36 PM
libc/src/math/generic/sinhf.cpp
59

It should either be:

// Sollya: fpminimax(sinh(x),[|1, 3,5,7|],[|D...|],[-1/16-1/64;1/16+1/64],x);

or

// Sollya: fpminimax(sinh(x) - x,[|3,5,7|],[|D...|],[-1/16-1/64;1/16+1/64],x);
60–62

Will this change the accuracy / throughput / latency for this range of inputs?

double x3 = x2 * xdbl;
double pe = fputil::polyeval(x2, 0x1.5555555556583p-3, 0x1.111110d239f1fp-7, 0x1.a02b5a284013cp-13);
return fputil::multiply_add(x3, pe, xdbl);
67–69

Add comments about your expanded formula / computations:

exp(x) = ep_p.mult_exp * (ep_p.r + 1)
exp(-x) = ep_m.mult_exp * (ep_m.r + 1)
sinh(x) = (exp(x) - exp(-x)) / 2 = ...
lntue added inline comments.Jul 19 2022, 9:45 PM
libc/test/src/math/sinhf_test.cpp
52

0.5 for tolerance?

60

0.5 for tolerance?

65

0.5 for tolerance?

orex updated this revision to Diff 448285.Jul 28 2022, 3:50 AM

Rebasing on main with small fixes.

orex edited the summary of this revision. (Show Details)Jul 28 2022, 4:00 AM
orex updated this revision to Diff 448319.Jul 28 2022, 6:08 AM
orex marked 6 inline comments as done.

Review fixes. More verbose comments.

libc/src/math/generic/sinhf.cpp
60–62

Performance:

I've checked it with core-math, reducing the range to [-0.08, 0.08]. The performance was the same with ~5% precision.

Precision:

The changes did not improve precision (the exceptional values still exceptional).
lntue added inline comments.Jul 28 2022, 6:24 AM
libc/src/math/generic/CMakeLists.txt
1141

Add expxf.h to HDRS and nearest_integer to DEPENDS

orex updated this revision to Diff 448324.Jul 28 2022, 6:48 AM

Review fixes.

lntue accepted this revision.Jul 28 2022, 7:27 AM

Looks good to me. Let's wait for @zimmermann6 to confirm the accuracy and performance.

This revision is now accepted and ready to land.Jul 28 2022, 7:27 AM
lntue added a comment.Jul 29 2022, 6:27 AM

@zimmermann6 is on vacation. You can go ahead and land this patch. He can comment on it later if there is any problem.

This revision was landed with ongoing or failed builds.Jul 29 2022, 8:24 AM
This revision was automatically updated to reflect the committed changes.