Skip to content

Commit

Permalink
8330094: RISC-V: Save and restore FRM in the call stub
Browse files Browse the repository at this point in the history
Reviewed-by: fyang
Backport-of: b0496096dc8d7dc7acf28aa006141a3ecea446de
  • Loading branch information
zifeihan authored and RealFYang committed May 5, 2024
1 parent 32bf1f4 commit 68a2d93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/frame_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
// Entry frames
// n.b. these values are determined by the layout defined in
// stubGenerator for the Java call stub
entry_frame_after_call_words = 34,
entry_frame_after_call_words = 35,
entry_frame_call_wrapper_offset = -10,

// we don't need a save area
Expand Down
27 changes: 24 additions & 3 deletions src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ class StubGenerator: public StubCodeGenerator {
// [ return_from_Java ] <--- sp
// [ argument word n ]
// ...
// -34 [ argument word 1 ]
// -33 [ saved f27 ] <--- sp_after_call
// -35 [ argument word 1 ]
// -34 [ saved FRM in Floating-point Control and Status Register ] <--- sp_after_call
// -33 [ saved f27 ]
// -32 [ saved f26 ]
// -31 [ saved f25 ]
// -30 [ saved f24 ]
Expand Down Expand Up @@ -165,8 +166,9 @@ class StubGenerator: public StubCodeGenerator {

// Call stub stack layout word offsets from fp
enum call_stub_layout {
sp_after_call_off = -33,
sp_after_call_off = -34,

frm_off = sp_after_call_off,
f27_off = -33,
f26_off = -32,
f25_off = -31,
Expand Down Expand Up @@ -214,6 +216,7 @@ class StubGenerator: public StubCodeGenerator {

const Address sp_after_call (fp, sp_after_call_off * wordSize);

const Address frm_save (fp, frm_off * wordSize);
const Address call_wrapper (fp, call_wrapper_off * wordSize);
const Address result (fp, result_off * wordSize);
const Address result_type (fp, result_type_off * wordSize);
Expand Down Expand Up @@ -296,6 +299,16 @@ class StubGenerator: public StubCodeGenerator {
__ fsd(f26, f26_save);
__ fsd(f27, f27_save);

__ frrm(t0);
__ sd(t0, frm_save);
// Set frm to the state we need. We do want Round to Nearest. We
// don't want non-IEEE rounding modes.
Label skip_fsrmi;
guarantee(__ RoundingMode::rne == 0, "must be");
__ beqz(t0, skip_fsrmi);
__ fsrmi(__ RoundingMode::rne);
__ bind(skip_fsrmi);

// install Java thread in global register now we have saved
// whatever value it held
__ mv(xthread, c_rarg7);
Expand Down Expand Up @@ -413,6 +426,14 @@ class StubGenerator: public StubCodeGenerator {

__ ld(x9, x9_save);

// restore frm
Label skip_fsrm;
__ ld(t0, frm_save);
__ frrm(t1);
__ beq(t0, t1, skip_fsrm);
__ fsrm(t0);
__ bind(skip_fsrm);

__ ld(c_rarg0, call_wrapper);
__ ld(c_rarg1, result);
__ ld(c_rarg2, result_type);
Expand Down

1 comment on commit 68a2d93

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.