File tree 3 files changed +43
-2
lines changed
3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
- //go:build 386 || amd64 || arm64 || ppc64 || ppc64le || s390x || wasm
5
+ //go:build 386 || amd64 || arm64 || ppc64 || ppc64le || riscv64 || s390x || wasm
6
6
7
7
package math
8
8
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
- //go:build !386 && !amd64 && !arm64 && !ppc64 && !ppc64le && !s390x && !wasm
5
+ //go:build !386 && !amd64 && !arm64 && !ppc64 && !ppc64le && !riscv64 && ! s390x && !wasm
6
6
7
7
package math
8
8
Original file line number Diff line number Diff line change
1
+ // Copyright 2023 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ #include "textflag.h"
6
+
7
+ #define PosInf 0x7FF0000000000000
8
+
9
+ // The rounding mode of RISC-V is different from Go spec.
10
+
11
+ #define ROUNDFN(NAME, MODE) \
12
+ TEXT NAME(SB),NOSPLIT,$0 ; \
13
+ MOVD x+0 (FP), F0; \
14
+ /* whether x is NaN */ ; \
15
+ FEQD F0, F0, X6; \
16
+ BNEZ X6, 3 (PC); \
17
+ /* return NaN if x is NaN */ ; \
18
+ MOVD F0, ret +8 (FP); \
19
+ RET ; \
20
+ MOV $PosInf, X6; \
21
+ FMVDX X6, F1; \
22
+ FABSD F0, F2; \
23
+ /* if abs(x) > +Inf, return Inf instead of round(x) */ ; \
24
+ FLTD F1, F2, X6; \
25
+ /* Inf should keep same signed with x then return */ ; \
26
+ BEQZ X6, 3 (PC); \
27
+ FCVTLD.MODE F0, X6; \
28
+ FCVTDL X6, F1; \
29
+ /* rounding will drop signed bit in RISCV, restore it */ ; \
30
+ FSGNJD F0, F1, F0; \
31
+ MOVD F0, ret +8 (FP); \
32
+ RET
33
+
34
+ // func archFloor(x float64) float64
35
+ ROUNDFN(·archFloor, RDN)
36
+
37
+ // func archCeil(x float64) float64
38
+ ROUNDFN(·archCeil, RUP)
39
+
40
+ // func archTrunc(x float64) float64
41
+ ROUNDFN(·archTrunc, RTZ)
You can’t perform that action at this time.
0 commit comments