-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8330094: RISC-V: Save and restore FRM in the call stub #18758
Conversation
👋 Welcome back mli! A progress list of the required criteria for merging this PR into |
@Hamlin-Li 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 94 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 |
@Hamlin-Li The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
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.
Looks good. Thanks.
BTW: There is another path where FP control register could got clobbered is through JNI.
See: https://bugs.openjdk.org/browse/JDK-8320892. I think we might want to fix it for riscv too.
@@ -415,6 +424,10 @@ class StubGenerator: public StubCodeGenerator { | |||
|
|||
__ ld(x9, x9_save); | |||
|
|||
// restore fcsr | |||
__ ld(t1, fcsr_save); | |||
__ csrw(CSR_FCSR, t1); |
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.
It would be better to avoid the csrw
in case the CSR is already set to RoundingMode::rne
on some hardware. You can have avoid it with a simple check on the current value of FCSR.
Something along the line of:
__ ld(t1, fcsr_save);
__ csrr(t0, CSR_FCSR);
__ beq(t1, t0, skip_csrw);
__ csrw(CSR_FCSR, t1);
__ bind(skip_csrw);
Some doc about it: https://riscv-optimization-guide.riseproject.dev/#_controlling_rounding_behavior_scalar
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.
Interesting. So is it safe to claim that csrr
is faster than csrw
? I didn't measure the difference.
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.
It's fair to claim that csrw
has side effects which may be more detrimental to performance, side effects that csrr
that doesn't have (and can't as it's only reading).
I didn't measure the difference.
I don't know how that affects current hardware, but remember that current hardware are in-order CPUs which may not be impacted by many of these performance problems.
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.
Another thing that is worth considering is that the fflags
(exception flags) contained in fcsr
is very likely to change after the Java call which does floating point calculations.
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.
Should we replace read/write/comp of fcsr with frm only?
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.
Yeah, that make sense to me. I think fflags
is safe to ignore here.
(And you will also need to update this code comment in file: src/hotspot/cpu/riscv/stubGenerator_riscv.cpp if you do that: // -34 [ saved Floating-point Control and Status Register ] <--- sp_after_call
)
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.
Thanks for discussion, all updated.
// don't want non-IEEE rounding modes. | ||
Label skip_fsrmi; | ||
__ mv(t1, __ RoundingMode::rne); | ||
__ beq(t0, t1, skip_fsrmi); |
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.
You can take advantage of RoundingMode::rne == 0
by doing __ beq(t0, zr, skip_fsrmi)
and remove the above __ mv(t1, __ RoundingMode::rne);
. Please add a guarantee(__ RoundingMode::rne == 0)
as well, just to self-document.
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.
Thanks, fixed.
// don't want non-IEEE rounding modes. | ||
Label skip_fsrmi; | ||
guarantee(__ RoundingMode::rne == 0, "must be"); | ||
__ beq(t0, zr, skip_fsrmi); |
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.
Suggestion: __ beqz(t0, skip_fsrmi);
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.
fixed, thanks
@@ -296,6 +299,16 @@ class StubGenerator: public StubCodeGenerator { | |||
__ fsd(f26, f26_save); | |||
__ fsd(f27, f27_save); | |||
|
|||
__ frrm(t0); | |||
__ sd(t0, frm_save); | |||
// Set fcsr to the state we need. We do want Round to Nearest. We |
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.
I think it will be more accurate to mention frm
instead of fcsr
in both code comment and the JBS title?
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.
agree, fixed
Thanks @luhenry @RealFYang for your reviewing. /integrate |
Going to push as commit b049609.
Your commit was automatically rebased without conflicts. |
@Hamlin-Li Pushed as commit b049609. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi,
Can you help to review this patch?
As discussed at #17745 (comment), we should do the similar thing as JDK-8319973 on aarch64.
Thanks!
Tests running ...
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18758/head:pull/18758
$ git checkout pull/18758
Update a local copy of the PR:
$ git checkout pull/18758
$ git pull https://git.openjdk.org/jdk.git pull/18758/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18758
View PR using the GUI difftool:
$ git pr show -t 18758
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18758.diff
Webrev
Link to Webrev Comment