-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8265325: Optimize StubRoutines::dpow() for Math.pow(x, 0.5) #3536
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
Conversation
/test |
👋 Welcome back jiefu! A progress list of the required criteria for merging this PR into |
@DamonFool |
@DamonFool The |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for testing all modes.
Note, when StubRoutines::dpow() is not used (-XX:-UseLibmIntrinsic or -XX:DisableIntrinsic=_pow) we use C code which also have this (and others) optimization already:
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/sharedRuntimeTrans.cpp#L483
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright (c) 2016, Intel Corporation. | |||
* Copyright (c) 2016, 2021, Intel Corporation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't modify copyright line of other company. Add new line for your company.
// pow(x, 0.5) isn't replaced with sqrt(x) for x < 0.0 | ||
if (a < 0.0) return; | ||
|
||
double r1 = Math.sqrt(a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r1
should be static value to avoid compiling sqrt()
method as intrinsic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r1
should be static value to avoid compilingsqrt()
method as intrinsic.
Hi @vnkozlov ,
Thanks for your review.
Patch has been updated based on your comments.
To be honest, I didn't get why r1 should be static value.
I think both static and non-static should be OK for the test.
So what would happen is sqrt() is intrinsified?
Could you please make it more clearer?
Thanks.
Best regards,
Jie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad. I thought to calculate sqrt(a)
outside test
method so that only pow()
code is tested.
Like calculating gold
value not in compiled code.
But the test have to use sqrt() for each value a
and sqrt
is 1 HW instruction so my suggestion was stupid.
Please, revert this change. Original test code was fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad. I thought to calculate
sqrt(a)
outsidetest
method so that onlypow()
code is tested.
Like calculatinggold
value not in compiled code.
But the test have to use sqrt() for each valuea
andsqrt
is 1 HW instruction so my suggestion was stupid.
Please, revert this change. Original test code was fine.
Thanks for your clarification.
I got your point.
Updated.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
@DamonFool 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:
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 35 new commits pushed to the
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. ➡️ To integrate this PR with the above commit message to the |
Thanks @vnkozlov . May I get a second review for this change? |
You need a second review for changes to Hotspot. I will provide it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
Thanks @neliasso . |
/integrate |
@DamonFool Since your change was applied there have been 37 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit b64a3fb. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi all,
I'd like to optimize the StubRoutines::dpow() for Math.pow(x, 0.5).
In the pow and sqrt discussion [1], Joe taught me that the Java library implementation of pow has been optimized for pow(x, 2.0) [2] and pow(x, 0.5) [3].
However, the hotspot StubRoutines::dpow() only implements the same opt for pow(x, 2.0), but still not for pow(x, 0.5).
This patch optimizes StubRoutines::dpow() for pow(x, 0.5).
Although not all Math.pow(x, 0.5) can be replaced with sqrt(x), we can still do it safely for the following cases:
The effect of this opt has been tested on serveral platforms showing 3.0x ~ 6.3x performance improvement.
And no performance drop was observed.
Testing:
Thanks.
Best regards,
Jie
[1] https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-April/076220.html
[2]
jdk/src/java.base/share/classes/java/lang/FdLibm.java
Line 362 in d84a7e5
[3]
jdk/src/java.base/share/classes/java/lang/FdLibm.java
Line 364 in d84a7e5
Detailed performance numbers:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3536/head:pull/3536
$ git checkout pull/3536
Update a local copy of the PR:
$ git checkout pull/3536
$ git pull https://git.openjdk.java.net/jdk pull/3536/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3536
View PR using the GUI difftool:
$ git pr show -t 3536
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3536.diff