Skip to content

Commit 9e582fc

Browse files
Boris UlasevichPaul Hohensee
Boris Ulasevich
authored and
Paul Hohensee
committed
8319973: AArch64: Save and restore FPCR in the call stub
Reviewed-by: aph
1 parent eaf1f67 commit 9e582fc

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Diff for: src/hotspot/cpu/aarch64/assembler_aarch64.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,8 @@ class Assembler : public AbstractAssembler {
10881088
#undef INSN
10891089

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

10941094
void msr(int op1, int CRn, int CRm, int op2, Register rt) {
10951095
starti;

Diff for: src/hotspot/cpu/aarch64/frame_aarch64.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
// Entry frames
9494
// n.b. these values are determined by the layout defined in
9595
// stubGenerator for the Java call stub
96-
entry_frame_after_call_words = 27,
96+
entry_frame_after_call_words = 29,
9797
entry_frame_call_wrapper_offset = -8,
9898

9999
// we don't need a save area

Diff for: src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,19 @@ class MacroAssembler: public Assembler {
570570
msr(0b011, 0b0100, 0b0100, 0b001, zr);
571571
}
572572

573+
// FPCR : op1 == 011
574+
// CRn == 0100
575+
// CRm == 0100
576+
// op2 == 000
577+
578+
inline void get_fpcr(Register reg) {
579+
mrs(0b11, 0b0100, 0b0100, 0b000, reg);
580+
}
581+
582+
inline void set_fpcr(Register reg) {
583+
msr(0b011, 0b0100, 0b0100, 0b000, reg);
584+
}
585+
573586
// DCZID_EL0: op1 == 011
574587
// CRn == 0000
575588
// CRm == 0000

Diff for: src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ class StubGenerator: public StubCodeGenerator {
136136
// [ return_from_Java ] <--- sp
137137
// [ argument word n ]
138138
// ...
139-
// -27 [ argument word 1 ]
139+
// -29 [ argument word 1 ]
140+
// -28 [ saved Floating-point Control Register ]
140141
// -26 [ saved v15 ] <--- sp_after_call
141142
// -25 [ saved v14 ]
142143
// -24 [ saved v13 ]
@@ -168,8 +169,9 @@ class StubGenerator: public StubCodeGenerator {
168169

169170
// Call stub stack layout word offsets from fp
170171
enum call_stub_layout {
171-
sp_after_call_off = -26,
172+
sp_after_call_off = -28,
172173

174+
fpcr_off = sp_after_call_off,
173175
d15_off = -26,
174176
d13_off = -24,
175177
d11_off = -22,
@@ -199,8 +201,9 @@ class StubGenerator: public StubCodeGenerator {
199201
StubCodeMark mark(this, "StubRoutines", "call_stub");
200202
address start = __ pc();
201203

202-
const Address sp_after_call(rfp, sp_after_call_off * wordSize);
204+
const Address sp_after_call (rfp, sp_after_call_off * wordSize);
203205

206+
const Address fpcr_save (rfp, fpcr_off * wordSize);
204207
const Address call_wrapper (rfp, call_wrapper_off * wordSize);
205208
const Address result (rfp, result_off * wordSize);
206209
const Address result_type (rfp, result_type_off * wordSize);
@@ -249,6 +252,14 @@ class StubGenerator: public StubCodeGenerator {
249252
__ stpd(v13, v12, d13_save);
250253
__ stpd(v15, v14, d15_save);
251254

255+
__ get_fpcr(rscratch1);
256+
__ str(rscratch1, fpcr_save);
257+
// Set FPCR to the state we need. We do want Round to Nearest. We
258+
// don't want non-IEEE rounding modes or floating-point traps.
259+
__ bfi(rscratch1, zr, 22, 4); // Clear DN, FZ, and Rmode
260+
__ bfi(rscratch1, zr, 8, 5); // Clear exception-control bits (8-12)
261+
__ set_fpcr(rscratch1);
262+
252263
// install Java thread in global register now we have saved
253264
// whatever value it held
254265
__ mov(rthread, c_rarg7);
@@ -362,6 +373,10 @@ class StubGenerator: public StubCodeGenerator {
362373
__ ldp(r22, r21, r22_save);
363374
__ ldp(r20, r19, r20_save);
364375

376+
// restore fpcr
377+
__ ldr(rscratch1, fpcr_save);
378+
__ set_fpcr(rscratch1);
379+
365380
__ ldp(c_rarg0, c_rarg1, call_wrapper);
366381
__ ldrw(c_rarg2, result_type);
367382
__ ldr(c_rarg3, method);

0 commit comments

Comments
 (0)