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

Open
wants to merge 1 commit into
base: master
Choose a base branch
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)

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

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@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?

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.

3 participants