public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6655] or1k: Support for softfloat to emulate hw exceptions
@ 2021-01-14  0:08 Stafford Horne
  0 siblings, 0 replies; only message in thread
From: Stafford Horne @ 2021-01-14  0:08 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b77f6d2fa848eca0aa04ff63aaeb52a54522e2aa

commit r11-6655-gb77f6d2fa848eca0aa04ff63aaeb52a54522e2aa
Author: Stafford Horne <shorne@gmail.com>
Date:   Fri Jan 24 21:30:31 2020 +0900

    or1k: Support for softfloat to emulate hw exceptions
    
    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.

Diff:
---
 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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-14  0:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14  0:08 [gcc r11-6655] or1k: Support for softfloat to emulate hw exceptions Stafford Horne

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).