From: Stafford Horne <shorne@gmail.com>
To: openrisc@lists.librecores.org
Subject: [OpenRISC] [PATCH 3/5] or1k: Support for softfloat to emulate hw exceptions
Date: Wed, 20 May 2020 05:37:48 +0900 [thread overview]
Message-ID: <20200519203750.401593-4-shorne@gmail.com> (raw)
In-Reply-To: <20200519203750.401593-1-shorne@gmail.com>
This allows the openrisc softfloat implementation to set exceptions.
This also sets the correct tininess after rounding value to be
consistent with hardware and simulator implementations.
libgcc/ChangeLog:
* config/or1k/sfp-machine.h (FP_RND_NEAREST, FP_RND_ZERO,
FP_RND_PINF, FP_RND_MINF, FP_RND_MASK, FP_EX_OVERFLOW,
FP_EX_UNDERFLOW, FP_EX_INEXACT, FP_EX_INVALID, FP_EX_DIVZERO,
FP_EX_ALL): New constant macros.
(_FP_DECL_EX, FP_ROUNDMODE, FP_INIT_ROUNDMODE,
FP_HANDLE_EXCEPTIONS): New macros.
(_FP_TININESS_AFTER_ROUNDING): Change to 1.
---
libgcc/config/or1k/sfp-machine.h | 41 +++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/libgcc/config/or1k/sfp-machine.h b/libgcc/config/or1k/sfp-machine.h
index 5da9e84990d..eebe5b0578e 100644
--- a/libgcc/config/or1k/sfp-machine.h
+++ b/libgcc/config/or1k/sfp-machine.h
@@ -41,12 +41,51 @@
R##_c = FP_CLS_NAN; \
} while (0)
+/* Handle getting and setting rounding mode for soft fp operations. */
+
+#define FP_RND_NEAREST (0x0 << 1)
+#define FP_RND_ZERO (0x1 << 1)
+#define FP_RND_PINF (0x2 << 1)
+#define FP_RND_MINF (0x3 << 1)
+#define FP_RND_MASK (0x3 << 1)
+
+#define FP_EX_OVERFLOW 1 << 3
+#define FP_EX_UNDERFLOW 1 << 4
+#define FP_EX_INEXACT 1 << 8
+#define FP_EX_INVALID 1 << 9
+#define FP_EX_DIVZERO 1 << 11
+#define FP_EX_ALL \
+ (FP_EX_INVALID | FP_EX_DIVZERO | FP_EX_OVERFLOW | FP_EX_UNDERFLOW \
+ | FP_EX_INEXACT)
+
+#define _FP_DECL_EX \
+ unsigned int _fpcsr __attribute__ ((unused)) = FP_RND_NEAREST
+
+#define FP_ROUNDMODE (_fpcsr & FP_RND_MASK)
+
+#ifdef __or1k_hard_float__
+#define FP_INIT_ROUNDMODE \
+do { \
+ __asm__ volatile ("l.mfspr %0,r0,20" : "=r" (_fpcsr)); \
+} while (0)
+
+#define FP_HANDLE_EXCEPTIONS \
+do { \
+ if (__builtin_expect (_fex, 0)) \
+ { \
+ _fpcsr &= ~FP_EX_ALL; \
+ _fpcsr |= _fex; \
+ __asm__ volatile ("l.mtspr r0,%0,20" : : "r" (_fpcsr)); \
+ } \
+} while (0)
+#endif
+
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#define __BYTE_ORDER __BIG_ENDIAN
-#define _FP_TININESS_AFTER_ROUNDING 0
+#define _FP_TININESS_AFTER_ROUNDING 1
/* Define ALIASNAME as a strong alias for NAME. */
# define strong_alias(name, aliasname) _strong_alias(name, aliasname)
--
2.26.2
next prev parent reply other threads:[~2020-05-19 20:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 1/5] or1k: Implement profile hook calling _mcount Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 2/5] or1k: Add builtin define to detect hard float Stafford Horne
2020-05-19 20:37 ` Stafford Horne [this message]
2020-05-19 20:37 ` [OpenRISC] [PATCH 4/5] or1k: Add note to indicate execstack Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 5/5] or1k: Fixup exception header data encodings Stafford Horne
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=20200519203750.401593-4-shorne@gmail.com \
--to=shorne@gmail.com \
--cc=openrisc@lists.librecores.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.