Skip to content

Commit

Permalink
8319973: AArch64: Save and restore FPCR in the call stub
Browse files Browse the repository at this point in the history
Reviewed-by: aph
  • Loading branch information
Boris Ulasevich authored and Paul Hohensee committed Oct 14, 2024
1 parent eaf1f67 commit 9e582fc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/cpu/aarch64/assembler_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,8 @@ class Assembler : public AbstractAssembler {
#undef INSN

// we only provide mrs and msr for the special purpose system
// registers where op1 (instr[20:19]) == 11 and, (currently) only
// use it for FPSR n.b msr has L (instr[21]) == 0 mrs has L == 1
// registers where op1 (instr[20:19]) == 11
// n.b msr has L (instr[21]) == 0 mrs has L == 1

void msr(int op1, int CRn, int CRm, int op2, Register rt) {
starti;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/frame_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 = 27,
entry_frame_after_call_words = 29,
entry_frame_call_wrapper_offset = -8,

// we don't need a save area
Expand Down
13 changes: 13 additions & 0 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,19 @@ class MacroAssembler: public Assembler {
msr(0b011, 0b0100, 0b0100, 0b001, zr);
}

// FPCR : op1 == 011
// CRn == 0100
// CRm == 0100
// op2 == 000

inline void get_fpcr(Register reg) {
mrs(0b11, 0b0100, 0b0100, 0b000, reg);
}

inline void set_fpcr(Register reg) {
msr(0b011, 0b0100, 0b0100, 0b000, reg);
}

// DCZID_EL0: op1 == 011
// CRn == 0000
// CRm == 0000
Expand Down
21 changes: 18 additions & 3 deletions src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class StubGenerator: public StubCodeGenerator {
// [ return_from_Java ] <--- sp
// [ argument word n ]
// ...
// -27 [ argument word 1 ]
// -29 [ argument word 1 ]
// -28 [ saved Floating-point Control Register ]
// -26 [ saved v15 ] <--- sp_after_call
// -25 [ saved v14 ]
// -24 [ saved v13 ]
Expand Down Expand Up @@ -168,8 +169,9 @@ class StubGenerator: public StubCodeGenerator {

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

fpcr_off = sp_after_call_off,
d15_off = -26,
d13_off = -24,
d11_off = -22,
Expand Down Expand Up @@ -199,8 +201,9 @@ class StubGenerator: public StubCodeGenerator {
StubCodeMark mark(this, "StubRoutines", "call_stub");
address start = __ pc();

const Address sp_after_call(rfp, sp_after_call_off * wordSize);
const Address sp_after_call (rfp, sp_after_call_off * wordSize);

const Address fpcr_save (rfp, fpcr_off * wordSize);
const Address call_wrapper (rfp, call_wrapper_off * wordSize);
const Address result (rfp, result_off * wordSize);
const Address result_type (rfp, result_type_off * wordSize);
Expand Down Expand Up @@ -249,6 +252,14 @@ class StubGenerator: public StubCodeGenerator {
__ stpd(v13, v12, d13_save);
__ stpd(v15, v14, d15_save);

__ get_fpcr(rscratch1);
__ str(rscratch1, fpcr_save);
// Set FPCR to the state we need. We do want Round to Nearest. We
// don't want non-IEEE rounding modes or floating-point traps.
__ bfi(rscratch1, zr, 22, 4); // Clear DN, FZ, and Rmode
__ bfi(rscratch1, zr, 8, 5); // Clear exception-control bits (8-12)
__ set_fpcr(rscratch1);

// install Java thread in global register now we have saved
// whatever value it held
__ mov(rthread, c_rarg7);
Expand Down Expand Up @@ -362,6 +373,10 @@ class StubGenerator: public StubCodeGenerator {
__ ldp(r22, r21, r22_save);
__ ldp(r20, r19, r20_save);

// restore fpcr
__ ldr(rscratch1, fpcr_save);
__ set_fpcr(rscratch1);

__ ldp(c_rarg0, c_rarg1, call_wrapper);
__ ldrw(c_rarg2, result_type);
__ ldr(c_rarg3, method);
Expand Down

0 comments on commit 9e582fc

Please sign in to comment.