Skip to content

Conversation

@missa-prime
Copy link
Contributor

@missa-prime missa-prime commented Apr 6, 2025

The goal of this PR is to implement an x86_64 intrinsic for java.lang.Math.cbrt() 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:CbrtPerf.CbrtPerfRanges"

The results of all tests posted below were captured with an Intel® Xeon 6761P using OpenJDK v25-b21 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 a major uplift of 169% when very small inputs are used and a more modest uplift of 45% for all other inputs.

Input range(s) Baseline throughput (ops/ms) Intrinsic throughput (ops/ms) Speedup
[-2^(-1022), 2^(-1022)] 6568 17678 2.69x
(-INF, -2^(-1022)], [2^(-1022), INF) 138932 200897 1.45x

Finally, the jtreg:test/jdk/java/lang/Math/CubeRootTests.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-8353686: Optimize Math.cbrt for x86 64 bit platforms (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24470

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 6, 2025

👋 Welcome back missa-prime! 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 Apr 6, 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:

8353686: Optimize Math.cbrt for x86 64 bit platforms

Reviewed-by: sviswanathan, sparasa, jbhateja

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 492 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, @jatin-bhateja) 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
Copy link

openjdk bot commented Apr 6, 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.

@missa-prime missa-prime force-pushed the user/missa-prime/cbrt branch from d1a152d to 30c48cb Compare April 6, 2025 07:16
@missa-prime missa-prime marked this pull request as ready for review April 25, 2025 20:09
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 25, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 25, 2025

Webrevs

@theRealAph
Copy link
Contributor

What are the monotonicity and accuracy results for this approximation? Is it correctly rounded or faithfully rounded?

@theRealAph
Copy link
Contributor

the built in cbrt micro-benchmark

How should we run that benchmark? Thanks.

@missa-prime
Copy link
Contributor Author

the built in cbrt micro-benchmark

How should we run that benchmark? Thanks.

make test TEST="micro:MathBench.cbrt"

@missa-prime
Copy link
Contributor Author

What are the monotonicity and accuracy results for this approximation? Is it correctly rounded or faithfully rounded?

  1. It's monotonic.
  2. It has a maximum error of 0.5213 ULP.
  3. It's not correctly rounded but it is faithfully rounded.

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.

This PR looks good to me. I independently ran the correctness tests and performance benchmarks.

Thanks,
Vamsi

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 May 28, 2025
@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 30, 2025
@openjdk
Copy link

openjdk bot commented May 30, 2025

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

@openjdk openjdk bot removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated labels May 30, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 30, 2025
@missa-prime
Copy link
Contributor Author

/integrate

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

openjdk bot commented May 30, 2025

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

@sviswa7
Copy link

sviswa7 commented May 30, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented May 30, 2025

Going to push as commit 0df8c96.
Since your change was applied there have been 492 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 May 30, 2025
@openjdk openjdk bot closed this May 30, 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 May 30, 2025
@openjdk
Copy link

openjdk bot commented May 30, 2025

@sviswa7 @missa-prime Pushed as commit 0df8c96.

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

@missa-prime missa-prime deleted the user/missa-prime/cbrt branch May 30, 2025 22:39
@eme64
Copy link
Contributor

eme64 commented May 31, 2025

@missa-prime The patch looks reasonable. It would have been nice if we (from Oracle) could have tested it before integration, especially this close to RDP1 for JDK25. Just for next time. If there are issues with it now, you risk that it gets backed out, and you have to redo it, and it does not make it into JDK25.

@dholmes-ora
Copy link
Member

This change also broke most of the non-x86 platforms, due to the new intrinsic not being implemented on those platforms.

@missa-prime
Copy link
Contributor Author

This change also broke most of the non-x86 platforms, due to the new intrinsic not being implemented on those platforms.

When you say "most of the non-x86 platforms", are you referring to the ones with processor types listed below?

  1. jdk/src/hotspot/cpu/arm
  2. jdk/src/hotspot/cpu/ppc
  3. jdk/src/hotspot/cpu/s390

I don't see a cbrt intrinsic implementation in the non-x86 platforms. However, the ones listed above appear to get to the ShouldNotReachHere error state if a particular intrinsic isn't found in TemplateInterpreterGenerator::generate_math_entry (templateInterpreterGenerator_*.cpp). It looks like aarch64 and riscv don't take that route and would fall back to the default cbrt implementation.

@dholmes-ora
Copy link
Member

When you say "most of the non-x86 platforms", are you referring to the ones with processor types listed below?

Yes - 3 of the 5 non-x86 platforms.

It looks like aarch64 and riscv don't take that route and would fall back to the default cbrt implementation.

I was wondering why Aarch64 didn't fail. I guess the other platforms may use this to detect new intrinsics being added.

@missa-prime
Copy link
Contributor Author

When you say "most of the non-x86 platforms", are you referring to the ones with processor types listed below?

Yes - 3 of the 5 non-x86 platforms.

It looks like aarch64 and riscv don't take that route and would fall back to the default cbrt implementation.

I was wondering why Aarch64 didn't fail. I guess the other platforms may use this to detect new intrinsics being added.

The arm, ppc, and s390 breaks are resolved by #25568.

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.

8 participants