Skip to content
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

8275167: x86 intrinsic for unsignedMultiplyHigh #5933

Closed
wants to merge 3 commits into from

Conversation

vamsi-parasa
Copy link
Contributor

@vamsi-parasa vamsi-parasa commented Oct 13, 2021

Optimize the new Math.unsignedMultiplyHigh using the x86 mul instruction. This change show 1.87X improvement on a micro benchmark.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5933/head:pull/5933
$ git checkout pull/5933

Update a local copy of the PR:
$ git checkout pull/5933
$ git pull https://git.openjdk.java.net/jdk pull/5933/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5933

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5933.diff

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Oct 13, 2021
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 13, 2021

Hi @vamsi-parasa, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user vamsi-parasa" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@vamsi-parasa
Copy link
Contributor Author

/covered

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label Oct 13, 2021
@openjdk
Copy link

openjdk bot commented Oct 13, 2021

@vamsi-parasa The following labels will be automatically applied to this pull request:

  • core-libs
  • 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.

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 13, 2021

Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@openjdk openjdk bot added hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Oct 13, 2021
@vamsi-parasa
Copy link
Contributor Author

/label hotspot-compiler

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Oct 13, 2021
@openjdk
Copy link

openjdk bot commented Oct 13, 2021

@vamsi-parasa
The hotspot-compiler label was successfully added.

@vamsi-parasa vamsi-parasa marked this pull request as ready for review October 13, 2021 21:30
@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels Oct 15, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 15, 2021
@mlbridge
Copy link

mlbridge bot commented Oct 15, 2021

Webrevs

@bplb
Copy link
Member

bplb commented Oct 15, 2021

The java.lang.Math change looks good, of course. On the rest I cannot comment but it is good to see something being done here.

// It is not worth trying to constant fold this stuff!
return TypeLong::LONG;
}

//=============================================================================
Copy link
Contributor

Choose a reason for hiding this comment

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

MulHiLNode::Value() and UMulHiLNode::Value() seem to be identical. Perhaps some refactoring would be in order, maybe make a common shared routine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do the refactoring to use a shared routine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed the refactored code to use a common routine for MulHiLNode::Value() and UMulHiLNode::Value(). Please review...

public long unsignedMultiplyHighLongLong() {
return Math.unsignedMultiplyHigh(long747, long13);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, the JMH overhead dominates when trying to measure the latency of events in the nanosecond range. unsignedMultiplyHigh should have a latency of maybe 1.5-2ns. Is that what you saw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the JMH overhead was dominating the measurement of latency. The latency observed for unsignedMultiplyHigh was 2.3ns with the intrinsic enabled.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

How you verified correctness of results?
I suggest to extend test/jdk//java/lang/Math/MultiplicationTests.java test to cover unsigned method.

@vamsi-parasa
Copy link
Contributor Author

How you verified correctness of results? I suggest to extend test/jdk//java/lang/Math/MultiplicationTests.java test to cover unsigned method.

Tests for unsignedMultiplyHigh were already added in test/jdk//java/lang/Math/MultiplicationTests.java (in July 2021 by Brian Burkhalter). Used that test to verify the correctness of the results.

@vnkozlov
Copy link
Contributor

How you verified correctness of results? I suggest to extend test/jdk//java/lang/Math/MultiplicationTests.java test to cover unsigned method.

Tests for unsignedMultiplyHigh were already added in test/jdk//java/lang/Math/MultiplicationTests.java (in July 2021 by Brian Burkhalter). Used that test to verify the correctness of the results.

Good. It seems I have old version of the test.
Did you run it with -Xcomp? How you verified that intrinsic is used?

@vamsi-parasa
Copy link
Contributor Author

How you verified correctness of results? I suggest to extend test/jdk//java/lang/Math/MultiplicationTests.java test to cover unsigned method.

Tests for unsignedMultiplyHigh were already added in test/jdk//java/lang/Math/MultiplicationTests.java (in July 2021 by Brian Burkhalter). Used that test to verify the correctness of the results.

Good. It seems I have old version of the test. Did you run it with -Xcomp? How you verified that intrinsic is used?

The tests were not run with -Xcomp. Looked at the generated x86 code using the disassembler (hsdis) and verified that that correct instruction (mul) instead of (imul, without the intrinsic) was being generated.

@vamsi-parasa
Copy link
Contributor Author

How you verified correctness of results? I suggest to extend test/jdk//java/lang/Math/MultiplicationTests.java test to cover unsigned method.

Tests for unsignedMultiplyHigh were already added in test/jdk//java/lang/Math/MultiplicationTests.java (in July 2021 by Brian Burkhalter). Used that test to verify the correctness of the results.

Good. It seems I have old version of the test. Did you run it with -Xcomp? How you verified that intrinsic is used?

I have verified that the intrinsic is being used by looking at the x86 assembly code generated by using perfasm profiler.

@vamsi-parasa vamsi-parasa reopened this Oct 20, 2021
@sviswa7
Copy link

sviswa7 commented Oct 20, 2021

The patch looks good to me.

@sviswa7
Copy link

sviswa7 commented Oct 20, 2021

@vnkozlov if the patch looks ok to you, could you please run this through your testing?

@openjdk
Copy link

openjdk bot commented Oct 20, 2021

⚠️ @vamsi-parasa the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout umult_high
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Oct 20, 2021

@vamsi-parasa 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:

8275167: x86 intrinsic for unsignedMultiplyHigh

Reviewed-by: kvn, sviswanathan

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 116 new commits pushed to the master branch:

  • cea3f01: 8275666: serviceability/jvmti/GetObjectSizeClass.java shouldn't have vm.flagless
  • d1e3ca4: 8233558: [TESTBUG] WindowOwnedByEmbeddedFrameTest.java fails on macos
  • 913f928: 8273507: Convert test/jdk/java/nio/channels/Channels/TransferTo.java to TestNG test
  • 0021a2f: 8275449: Add linux-aarch64-zero build profile
  • 46b5bfb: 8233648: [TESTBUG] DefaultMenuBarTest.java failing on macos
  • bbc6061: 8272614: Unused parameters in MethodHandleNatives linking methods
  • 7e28bdd: 8275055: Improve HeapRegionRemSet::split_card()
  • 35e5bb5: 8269336: Malformed jdk.serialFilter incorrectly handled
  • 043cde2: 8275319: java.net.NetworkInterface throws java.lang.Error instead of SocketException
  • a91a0a5: 8233724: Remove -Wc++14-compat warning suppression in operator_new.cpp
  • ... and 106 more: https://git.openjdk.java.net/jdk/compare/124f82377ba93359bc59118ee315ba194080fa92...master

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 (@vnkozlov, @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 ready Pull request is ready to be integrated label Oct 20, 2021
Copy link
Contributor

@vnkozlov vnkozlov 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. And I submitted testing.

@vnkozlov
Copy link
Contributor

Tests passed. You can integrate changes.

@vamsi-parasa
Copy link
Contributor Author

Tests passed. You can integrate changes.

Thanks Vladimir! What are the next steps to integrate the change?

@vamsi-parasa
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 20, 2021
@openjdk
Copy link

openjdk bot commented Oct 20, 2021

@vamsi-parasa
Your change (at version a10a9fb) is now ready to be sponsored by a Committer.

@sviswa7
Copy link

sviswa7 commented Oct 20, 2021

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 20, 2021

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

  • cea3f01: 8275666: serviceability/jvmti/GetObjectSizeClass.java shouldn't have vm.flagless
  • d1e3ca4: 8233558: [TESTBUG] WindowOwnedByEmbeddedFrameTest.java fails on macos
  • 913f928: 8273507: Convert test/jdk/java/nio/channels/Channels/TransferTo.java to TestNG test
  • 0021a2f: 8275449: Add linux-aarch64-zero build profile
  • 46b5bfb: 8233648: [TESTBUG] DefaultMenuBarTest.java failing on macos
  • bbc6061: 8272614: Unused parameters in MethodHandleNatives linking methods
  • 7e28bdd: 8275055: Improve HeapRegionRemSet::split_card()
  • 35e5bb5: 8269336: Malformed jdk.serialFilter incorrectly handled
  • 043cde2: 8275319: java.net.NetworkInterface throws java.lang.Error instead of SocketException
  • a91a0a5: 8233724: Remove -Wc++14-compat warning suppression in operator_new.cpp
  • ... and 106 more: https://git.openjdk.java.net/jdk/compare/124f82377ba93359bc59118ee315ba194080fa92...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Oct 20, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and 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 Oct 20, 2021
@openjdk
Copy link

openjdk bot commented Oct 20, 2021

@sviswa7 @vamsi-parasa Pushed as commit af7c56b.

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

@@ -1390,6 +1390,7 @@ public static long multiplyHigh(long x, long y) {
* @see #multiplyHigh
* @since 18
*/
@IntrinsicCandidate
public static long unsignedMultiplyHigh(long x, long y) {
// Compute via multiplyHigh() to leverage the intrinsic
Copy link

@ijuma ijuma Oct 23, 2021

Choose a reason for hiding this comment

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

Hi @ijuma, thanks for making a comment in an OpenJDK project!

All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user ijuma for the summary.

If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.

Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for spotting the stale comment. It will removed in another related commit that will be pushed soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
6 participants