This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] soft-fp handling of underflow


From: "Joseph S. Myers" <joseph@codesourcery.com>
Date: Wed, 30 May 2012 09:45:16 +0000 (UTC)

> This patch is OK with an appropriate ChangeLog entry (and 2012 added to 
> the copyright dates in op-common.h; we don't yet use ranges of years in 
> the copyright notices in soft-fp because GCC's README doesn't yet have a 
> notice about the meaning of such ranges).

Done, as below, thanks for reviewing Joseph.

Can you please give some feedback about the FP_EX_DENORM issue on
powerpc?  I can't see it being right to generate underflow just
because an input operand is a subnormal.  It can be just a "tiny"
one, and in any event underflow is a property of the result we
calculate not of the input operands.

Thanks again.

--------------------
Fix underflow generation in soft-fp.

	* soft-fp/soft-fp.h (FP_CUR_EXCEPTIONS): Define.
	(FP_TRAPPING_EXCEPTIONS): Provide default implementation.
	* sysdeps/sparc/sparc32/soft-fp/sfp-machine.h
	(FP_TRAPPING_EXCEPTIONS): Define.
	* sysdeps/sparc/sparc64/soft-fp/sfp-machine.h
	(FP_TRAPPING_EXCEPTIONS): Define.
	* soft-fp/op-common.h (_FP_PACK_SEMIRAW): Signal underflow for
	subnormals only when inexact has been signalled or underflow
	exceptions are enabled.
	(_FP_PACK_CANONICAL): Likewise.
---
 ChangeLog                                   |   13 +++++++++++++
 soft-fp/op-common.h                         |   13 ++++++++++---
 soft-fp/soft-fp.h                           |    7 +++++++
 sysdeps/sparc/sparc32/soft-fp/sfp-machine.h |    3 ++-
 sysdeps/sparc/sparc64/soft-fp/sfp-machine.h |    3 ++-
 5 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 42df8d7..4adb73a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-05-30  David S. Miller  <davem@davemloft.net>
+
+	* soft-fp/soft-fp.h (FP_CUR_EXCEPTIONS): Define.
+	(FP_TRAPPING_EXCEPTIONS): Provide default implementation.
+	* sysdeps/sparc/sparc32/soft-fp/sfp-machine.h
+	(FP_TRAPPING_EXCEPTIONS): Define.
+	* sysdeps/sparc/sparc64/soft-fp/sfp-machine.h
+	(FP_TRAPPING_EXCEPTIONS): Define.
+	* soft-fp/op-common.h (_FP_PACK_SEMIRAW): Signal underflow for
+	subnormals only when inexact has been signalled or underflow
+	exceptions are enabled.
+	(_FP_PACK_CANONICAL): Likewise.
+
 2012-05-30  H.J. Lu  <hongjiu.lu@intel.com>
 
 	[BZ #14183]
diff --git a/soft-fp/op-common.h b/soft-fp/op-common.h
index b70026f..db75af5 100644
--- a/soft-fp/op-common.h
+++ b/soft-fp/op-common.h
@@ -1,5 +1,5 @@
 /* Software floating-point emulation. Common operations.
-   Copyright (C) 1997,1998,1999,2006,2007 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2006,2007,2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson (rth@cygnus.com),
 		  Jakub Jelinek (jj@ultra.linux.cz),
@@ -146,7 +146,11 @@ do {								\
   if (!_FP_EXP_NORMAL(fs, wc, X) && !_FP_FRAC_ZEROP_##wc(X))	\
     {								\
       if (X##_e == 0)						\
-	FP_SET_EXCEPTION(FP_EX_UNDERFLOW);			\
+	{							\
+	  if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT)		\
+	      || (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW))	\
+	    FP_SET_EXCEPTION(FP_EX_UNDERFLOW);			\
+	}							\
       else							\
 	{							\
 	  if (!_FP_KEEPNANFRACP)				\
@@ -226,13 +230,16 @@ do {								\
 	      {							\
 	        X##_e = 1;					\
 	        _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc);	\
+		FP_SET_EXCEPTION(FP_EX_INEXACT);		\
 	      }							\
 	    else						\
 	      {							\
 		X##_e = 0;					\
 		_FP_FRAC_SRL_##wc(X, _FP_WORKBITS);		\
-		FP_SET_EXCEPTION(FP_EX_UNDERFLOW);		\
 	      }							\
+	    if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT)		\
+		|| (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW))	\
+	      FP_SET_EXCEPTION(FP_EX_UNDERFLOW);		\
 	  }							\
 	else							\
 	  {							\
diff --git a/soft-fp/soft-fp.h b/soft-fp/soft-fp.h
index 46cb1cf..750c7fe 100644
--- a/soft-fp/soft-fp.h
+++ b/soft-fp/soft-fp.h
@@ -128,6 +128,13 @@
 #define FP_CLEAR_EXCEPTIONS				\
   _fex = 0
 
+#define FP_CUR_EXCEPTIONS				\
+  (_fex)
+
+#ifndef FP_TRAPPING_EXCEPTIONS
+#define FP_TRAPPING_EXCEPTIONS 0
+#endif
+
 #define _FP_ROUND_NEAREST(wc, X)			\
 do {							\
     if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND)	\
diff --git a/sysdeps/sparc/sparc32/soft-fp/sfp-machine.h b/sysdeps/sparc/sparc32/soft-fp/sfp-machine.h
index 4314082..e60f1ca 100644
--- a/sysdeps/sparc/sparc32/soft-fp/sfp-machine.h
+++ b/sysdeps/sparc/sparc32/soft-fp/sfp-machine.h
@@ -1,6 +1,6 @@
 /* Machine-dependent software floating-point definitions.
    Sparc userland (_Q_*) version.
-   Copyright (C) 1997,1998,1999, 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2002,2006,2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson (rth@cygnus.com),
 		  Jakub Jelinek (jj@ultra.linux.cz) and
@@ -192,6 +192,7 @@ do {								\
   _FPU_GETCW(_fcw);						\
 } while (0)
 
+#define FP_TRAPPING_EXCEPTIONS ((_fcw >> 23) & 0x1f)
 #define FP_INHIBIT_RESULTS ((_fcw >> 23) & _fex)
 
 /* Simulate exceptions using double arithmetics. */
diff --git a/sysdeps/sparc/sparc64/soft-fp/sfp-machine.h b/sysdeps/sparc/sparc64/soft-fp/sfp-machine.h
index 36f92d6..9bd4298 100644
--- a/sysdeps/sparc/sparc64/soft-fp/sfp-machine.h
+++ b/sysdeps/sparc/sparc64/soft-fp/sfp-machine.h
@@ -1,6 +1,6 @@
 /* Machine-dependent software floating-point definitions.
    Sparc64 userland (_Q_* and _Qp_*) version.
-   Copyright (C) 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2006, 2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson (rth@cygnus.com),
 		  Jakub Jelinek (jj@ultra.linux.cz) and
@@ -100,6 +100,7 @@ do {								\
   _FPU_GETCW(_fcw);						\
 } while (0)
 
+#define FP_TRAPPING_EXCEPTIONS ((_fcw >> 23) & 0x1f)
 #define FP_INHIBIT_RESULTS ((_fcw >> 23) & _fex)
 
 /* Simulate exceptions using double arithmetics. */
-- 
1.7.10


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]