Text file
src/math/floor_riscv64.s
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)
42
View as plain text