public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Shiqi Zhang <shiqi@isrc.iscas.ac.cn>
To: libc-alpha@sourceware.org
Cc: Shiqi Zhang <shiqi@isrc.iscas.ac.cn>
Subject: [PATCH] riscv: Add macros for FPUCW in fpu_control.h
Date: Sun, 12 Feb 2023 01:49:16 +0800	[thread overview]
Message-ID: <20230211174916.1455-1-shiqi@isrc.iscas.ac.cn> (raw)

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

Reference: RISC-V Unprivileged Spec v20191213, Section 11.2, Table 11.1 & 11.2
---
I'm implementing RISC-V support for netlib/f2c, and found that
there is no definitions for FPCSR flag bits in glibc when writing codes
for FPU exception controls. So I checked them in RISC-V specs and
defined the accrued exception flags and rounding mode flags in this
patch, making it easier for other users to control FPU status.

Also, 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.

For copyrights, this patch is covered by an existing copyright
assignment of ISCAS/ISRC so I'm assuming that there shouldn't be a
signed-off-by line in commit message.

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

diff --git a/sysdeps/riscv/fpu_control.h b/sysdeps/riscv/fpu_control.h
index c33798c6bb..5c883be4fe 100644
--- a/sysdeps/riscv/fpu_control.h
+++ b/sysdeps/riscv/fpu_control.h
@@ -36,6 +36,21 @@ 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)
+# define _FPU_RM_DYN (7 << 5)
+
+/* FPU accrued exception flags */
+# define _FPU_EXCEPT_NV (1 << 0)
+# define _FPU_EXCEPT_NZ (1 << 1)
+# define _FPU_EXCEPT_OF (1 << 2)
+# define _FPU_EXCEPT_UF (1 << 3)
+# define _FPU_EXCEPT_NX (1 << 4)
+
 /* Type of the control word.  */
 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
 
-- 
2.39.1


             reply	other threads:[~2023-02-11 17:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-11 17:49 Shiqi Zhang [this message]
2023-02-11 20:21 ` Andreas Schwab
2023-02-12  6:29   ` Shiqi Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230211174916.1455-1-shiqi@isrc.iscas.ac.cn \
    --to=shiqi@isrc.iscas.ac.cn \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).