1 /* Copyright (c) 2017 SiFive Inc. All rights reserved.
3 This copyrighted material is made available to anyone wishing to use,
4 modify, copy, or redistribute it subject to the terms and conditions
5 of the FreeBSD License. This program is distributed in the hope that
6 it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7 including the implied warranties of MERCHANTABILITY or FITNESS FOR
8 A PARTICULAR PURPOSE. A copy of this license is available at
9 http://www.opensource.org/licenses.
14 #if defined(__riscv_flen) || defined (__riscv_zfinx)
18 asm volatile ("fscsr %0" :: "r"(value
));
25 asm volatile ("frcsr %0" : "=r" (value
));
30 frm_fp_rnd (unsigned frm
)
38 /* 4 ~ 7 is invalid value, so just retun FP_RP. */
44 frm_fp_except (unsigned except
)
47 if (except
& (1 << 0))
49 if (except
& (1 << 1))
51 if (except
& (1 << 2))
53 if (except
& (1 << 3))
55 if (except
& (1 << 4))
61 frm_except(fp_except fp
)
77 #endif /* __riscv_flen */
88 #if defined(__riscv_flen) || defined (__riscv_zfinx)
89 unsigned rm
= (frsr () >> 5) & 0x7;
90 return frm_fp_rnd (rm
);
93 #endif /* __riscv_flen */
99 #if defined(__riscv_flen) || defined (__riscv_zfinx)
100 return frm_fp_except(frsr ());
103 #endif /* __riscv_flen */
107 fpsetmask(fp_except mask
)
113 fpsetround(fp_rnd rnd_dir
)
115 #if defined(__riscv_flen) || defined (__riscv_zfinx)
116 unsigned fsr
= frsr ();
117 unsigned rm
= (fsr
>> 5) & 0x7;
121 case FP_RN
: new_rm
= 0; break;
122 case FP_RZ
: new_rm
= 1; break;
123 case FP_RM
: new_rm
= 2; break;
124 case FP_RP
: new_rm
= 3; break;
127 fssr (new_rm
<< 5 | fsr
& 0x1f);
128 return frm_fp_rnd (rm
);
131 #endif /* __riscv_flen */
135 fpsetsticky(fp_except sticky
)
137 #if defined(__riscv_flen) || defined (__riscv_zfinx)
138 unsigned fsr
= frsr ();
139 fssr (frm_except(sticky
) | (fsr
& ~0x1f));
140 return frm_fp_except(fsr
);
143 #endif /* __riscv_flen */