public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] riscv: Add macros for FPUCW/fcsr in fpu_control.h
@ 2023-02-12  6:52 Shiqi Zhang
  2023-02-12 19:36 ` Richard Henderson
  0 siblings, 1 reply; 8+ messages in thread
From: Shiqi Zhang @ 2023-02-12  6:52 UTC (permalink / raw)
  To: libc-alpha; +Cc: schwab, Shiqi Zhang

Add macros for rounding modes and accrued exception flags in order to
make controlling fcsr easier for users.

Reference: RISC-V Unprivileged Spec v20191213, Section 11.2: Figure 11.2, Table 11.1 & 11.2
---
Fixed careless mistakes in v1 and removed invalid rounding mode DYN.

Still, I think these macros should be documented somewhere but I'm
not sure where should I doc them. I'll appreciate it if you could give
some suggestions.

Regards,
Shiqi Zhang

 sysdeps/riscv/fpu_control.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sysdeps/riscv/fpu_control.h b/sysdeps/riscv/fpu_control.h
index c33798c6bb..1dcadd3ea1 100644
--- a/sysdeps/riscv/fpu_control.h
+++ b/sysdeps/riscv/fpu_control.h
@@ -36,6 +36,20 @@ extern fpu_control_t __fpu_control;
 # define _FPU_DEFAULT  0
 # define _FPU_IEEE     _FPU_DEFAULT
 
+/* FPU rounding modes */
+# define _FPU_RM_RNE (0 << 5)
+# define _FPU_RM_RTZ (1 << 5)
+# define _FPU_RM_RDN (2 << 5)
+# define _FPU_RM_RUP (3 << 5)
+# define _FPU_RM_RMM (4 << 5)
+
+/* FPU accrued exception flags */
+# define _FPU_EXCEPT_NV (1 << 4)
+# define _FPU_EXCEPT_DZ (1 << 3)
+# define _FPU_EXCEPT_OF (1 << 2)
+# define _FPU_EXCEPT_UF (1 << 1)
+# define _FPU_EXCEPT_NX (1 << 0)
+
 /* Type of the control word.  */
 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
 
-- 
2.39.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-02-13 22:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-12  6:52 [PATCH v2] riscv: Add macros for FPUCW/fcsr in fpu_control.h Shiqi Zhang
2023-02-12 19:36 ` Richard Henderson
2023-02-13  6:16   ` Shiqi Zhang
2023-02-13  8:39     ` Andreas Schwab
2023-02-13 10:17       ` Shiqi Zhang
2023-02-13 22:00         ` Joseph Myers
2023-02-13 18:17     ` Richard Henderson
2023-02-13 19:31       ` Shiqi Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).