Skip to content

8360559: Optimize Math.sinh for x86 64 bit platforms #26152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

missa-prime
Copy link
Contributor

@missa-prime missa-prime commented Jul 7, 2025

The goal of this PR is to implement an x86_64 intrinsic for java.lang.Math.sinh() using libm. There is a new set of micro-benchmarks are included to check the performance of specific input value ranges to help prevent regressions in the future.

The command to run all range specific micro-benchmarks is posted below.

make test TEST="micro:SinhPerf.SinhPerfRanges"

The results of all tests posted below were captured with an Intel® Xeon 8488C using OpenJDK v26-b4 as the baseline version.

For performance data collected with the new built in range micro-benchmark, see the table below. Each result is the mean of 8 individual runs, and the input ranges used match those from the original Java implementation. Overall, the intrinsic provides an an average uplift of 64% when input values fall into the middle three ranges where heavy computation is required. However, very small inputs and very large inputs show drops of 74% and 66% respectively.

Input range(s) Baseline throughput (ops/ms) Intrinsic throughput (ops/ms) Speedup
[-2^(-28), 2^(-28)] 844160 216029 0.26x
[-22, -2^(-28)], [2^(-28), 22] 81662 157351 1.93x
[-709.78, -22], [22, 709.78] 119075 167635 1.41x
[-710.48, -709.78], [709.78, 710.48] 111636 177125 1.59x
(-INF, -710.48], [710.48, INF) 959296 313839 0.33x

Finally, the jtreg:test/jdk/java/lang/Math/HyperbolicTests.java test passed with the changes.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8360559: Optimize Math.sinh for x86 64 bit platforms (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26152/head:pull/26152
$ git checkout pull/26152

Update a local copy of the PR:
$ git checkout pull/26152
$ git pull https://git.openjdk.org/jdk.git pull/26152/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26152

View PR using the GUI difftool:
$ git pr show -t 26152

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26152.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 7, 2025

👋 Welcome back missa! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 7, 2025

@missa-prime This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8360559: Optimize Math.sinh for x86 64 bit platforms

Reviewed-by: sviswanathan, sparasa

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 467 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@sviswa7) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 7, 2025
@openjdk
Copy link

openjdk bot commented Jul 7, 2025

@missa-prime The following labels will be automatically applied to this pull request:

  • core-libs
  • graal
  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Jul 7, 2025

Webrevs

@fweimer-rh
Copy link

Isn't this effectively a libm benchmark (where the sinh implementation resides)? Please include the libm version for reference here. Thanks.

@jddarcy
Copy link
Member

jddarcy commented Jul 7, 2025

Are there plans for a cosh intrinsic as follow-up work? There was a previous effort to intrinsify tanh.

@jddarcy
Copy link
Member

jddarcy commented Jul 7, 2025

A large fraction of floating-point numbers are in the [-2^(-28), 2^(-28)] range where there is a performance degradation with the new implementation.

What is the expected distribution of arguments to sinh?

@missa-prime
Copy link
Contributor Author

A large fraction of floating-point numbers are in the [-2^(-28), 2^(-28)] range where there is a performance degradation with the new implementation.

What is the expected distribution of arguments to sinh?

I don't know about an expected distribution of distribution of arguments to sinh. From glancing through research papers though, I get the sense that the [-2^(-28), 2^(-28)] range isn't used all that much. A couple of papers showing this are linked below.

  1. An Analysis of the Hyperbolic Bid Stacking Technique's Use in Modeling Power Prices
  2. Experimental Validation of a 3GPP compliant 5G-based Positioning System

I think the [-2^(-28), 2^(-28)] range isn't all that interesting for sinh anyway as it just returns the input itself. So, I doubt any applications are relying all that heavily on it.

@missa-prime
Copy link
Contributor Author

Are there plans for a cosh intrinsic as follow-up work? There was a previous effort to intrinsify tanh.

Yes, the intention is to have cosh as next math intrinsic.

@missa-prime
Copy link
Contributor Author

Isn't this effectively a libm benchmark (where the sinh implementation resides)? Please include the libm version for reference here. Thanks.

I'm not sure which libm version you're referring to. The only current sinh benchmark I'm aware of is in MathBench.java, and the benchmarks in SinhPerf.java didn't exist until now. Could you clarify?

@jddarcy
Copy link
Member

jddarcy commented Jul 10, 2025

What is the accuracy of the algorithm in ulps (units the last place)?

The java.lang.Math specification has max error and various other accuracy requirements any implementation must meet.

@fweimer-rh
Copy link

I'm not sure which libm version you're referring to. The only current sinh benchmark I'm aware of is in MathBench.java, and the benchmarks in SinhPerf.java didn't exist until now. Could you clarify?

I didn't notice the code you ported over from the Intel math library at first. I assumed “libm” referred to the system libm version.

@missa-prime
Copy link
Contributor Author

What is the accuracy of the algorithm in ulps (units the last place)?

The java.lang.Math specification has max error and various other accuracy requirements any implementation must meet.

0.51 ulps

@jddarcy
Copy link
Member

jddarcy commented Jul 10, 2025

What is the accuracy of the algorithm in ulps (units the last place)?
The java.lang.Math specification has max error and various other accuracy requirements any implementation must meet.

0.51 ulps

Please add that as a comment to the changeset.

Also, if the worst-case inputs for this algorithm are known, they should the added as part of the core libraries regression tests for the math library.

@missa-prime
Copy link
Contributor Author

What is the accuracy of the algorithm in ulps (units the last place)?
The java.lang.Math specification has max error and various other accuracy requirements any implementation must meet.

0.51 ulps

Please add that as a comment to the changeset.

Also, if the worst-case inputs for this algorithm are known, they should the added as part of the core libraries regression tests for the math library.

I included the error bound as a separate section of the comment header in the stub generator source file. Also, the input ranges are covered in jtreg:test/jdk/java/lang/Math/HyperbolicTests.java.

Copy link
Contributor

@vamsi-parasa vamsi-parasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the code, ran the benchmarks and correctness test and verified that it's passing. This PR looks good to me.

Copy link

@sviswa7 sviswa7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 31, 2025
@missa-prime
Copy link
Contributor Author

@eme64 Available to run the additional tests? Also, a couple of the pre-submit checks had failures unrelated to the code changes.

@missa-prime
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Aug 4, 2025
@openjdk
Copy link

openjdk bot commented Aug 4, 2025

@missa-prime
Your change (at version 3ab7ab3) is now ready to be sponsored by a Committer.

@sviswa7
Copy link

sviswa7 commented Aug 4, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Aug 4, 2025

Going to push as commit 05f8a6f.
Since your change was applied there have been 467 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 4, 2025
@openjdk openjdk bot closed this Aug 4, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Aug 4, 2025
@openjdk
Copy link

openjdk bot commented Aug 4, 2025

@sviswa7 @missa-prime Pushed as commit 05f8a6f.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@RogerRiggs
Copy link
Contributor

RogerRiggs commented Aug 4, 2025

This seems to be failing in the CI on the build of: linux-x64-debug-nopch

[2025-08-04T19:02:29,373Z] /......../workspace/open/src/hotspot/cpu/x86/stubGenerator_x86_64_sinh.cpp:293:27: error: 'stub_id' was not declared in this scope; did you mean 'StubId'?
[2025-08-04T19:02:29,373Z]   293 |   StubCodeMark mark(this, stub_id);
[2025-08-04T19:02:29,373Z]       |                           ^~~~~~~
[2025-08-04T19:02:29,373Z]       |                           StubId
[2025-08-04T19:02:29,373Z] 

@missa-prime
Copy link
Contributor Author

This seems to be failing in the CI on the build of: linux-x64-debug-nopch

[2025-08-04T19:02:29,373Z] /......../workspace/open/src/hotspot/cpu/x86/stubGenerator_x86_64_sinh.cpp:293:27: error: 'stub_id' was not declared in this scope; did you mean 'StubId'?
[2025-08-04T19:02:29,373Z]   293 |   StubCodeMark mark(this, stub_id);
[2025-08-04T19:02:29,373Z]       |                           ^~~~~~~
[2025-08-04T19:02:29,373Z]       |                           StubId
[2025-08-04T19:02:29,373Z] 

Thanks for notification. It looks like an incorrect type declaration. I'll submit a fix.

@missa-prime missa-prime deleted the user/missa-prime/sinh branch August 4, 2025 20:21
@eme64
Copy link
Contributor

eme64 commented Aug 19, 2025

@missa-prime I was on vacation for a few weeks. Feel free to ping others when I don't respond ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

7 participants