aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorGuoqi Chen <chenguoqi@loongson.cn>2026-04-01 09:13:37 +0800
committerabner chenc <chenguoqi@loongson.cn>2026-04-06 18:18:32 -0700
commite76c910108577c93651dff7481034d2d5b933c14 (patch)
tree595180526b2496c96958901946925ee3e5d8360c /src/runtime
parentf9f351b130d10ea1623ac0423d3ca9e4b07e3502 (diff)
downloadgo-e76c910108577c93651dff7481034d2d5b933c14.tar.xz
runtime: save and restore fcsr0 registers in async preempt on loong64
Currently, all Op implementations on loong64 do not modify the FCSR (floating point control status register), but users can modify the FCSR for special floating point computing needs. FCSR is also saved and restored in the fpu context of the Linux kernel [1]. [1]: https://github.com/torvalds/linux/blob/master/arch/loongarch/kernel/fpu.S#L565C1-L566C1 Change-Id: I776e72dfcc1f027bfe8d22aa2eae453100a6ee1c Reviewed-on: https://go-review.googlesource.com/c/go/+/761720 Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/mkpreempt.go7
-rw-r--r--src/runtime/preempt_loong64.s12
2 files changed, 15 insertions, 4 deletions
diff --git a/src/runtime/mkpreempt.go b/src/runtime/mkpreempt.go
index ca1c6e4a0e..8d7b3e7ceb 100644
--- a/src/runtime/mkpreempt.go
+++ b/src/runtime/mkpreempt.go
@@ -759,6 +759,13 @@ func genLoong64(g *gen) {
mov+" %d(R3), R5\n"+rs,
regsize)
+ // Add floating point control/status register fcsr0,
+ // fcsr1~fcsr3 are aliases for some fields in fcsr0.
+ l.addSpecial(
+ mov+" FCSR0, R5\n"+mov+" R5, %d(R3)",
+ mov+" %d(R3), R5\n"+mov+" R5, FCSR0",
+ regsize)
+
// Create layouts for lasx, lsx and fp registers.
lasxRegs := layout{sp: xReg}
lsxRegs := lasxRegs
diff --git a/src/runtime/preempt_loong64.s b/src/runtime/preempt_loong64.s
index 4bc7ea3947..562f97780a 100644
--- a/src/runtime/preempt_loong64.s
+++ b/src/runtime/preempt_loong64.s
@@ -4,8 +4,8 @@
#include "textflag.h"
TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
- MOVV R1, -224(R3)
- SUBV $224, R3
+ MOVV R1, -232(R3)
+ SUBV $232, R3
// Save GPs
MOVV R4, 8(R3)
MOVV R5, 16(R3)
@@ -50,6 +50,8 @@ TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
MOVV FCC7, R4
BSTRINSV $63, R4, $56, R5
MOVV R5, 216(R3)
+ MOVV FCSR0, R5
+ MOVV R5, 224(R3)
// Save extended register state to p.xRegs.scratch
MOVV g_m(g), R4
MOVV m_p(R4), R4
@@ -272,6 +274,8 @@ restoreLASX:
XVMOVQ 0(R4), X0
// Restore GPs
restoreGPs:
+ MOVV 224(R3), R5
+ MOVV R5, FCSR0
MOVV 216(R3), R5
BSTRPICKV $7, R5, $0, R4
MOVV R4, FCC0
@@ -315,7 +319,7 @@ restoreGPs:
MOVV 24(R3), R6
MOVV 16(R3), R5
MOVV 8(R3), R4
- MOVV 224(R3), R1
+ MOVV 232(R3), R1
MOVV (R3), R30
- ADDV $232, R3
+ ADDV $240, R3
JMP (R30)