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]

soft-fp: add macro FP_NO_EXCEPTIONS


This patch adds a macro FP_NO_EXCEPTIONS to soft-fp, that can be
defined before including soft-fp.h to cause certain macros relating to
exceptions and rounding modes to be stubbed out.  This means that
FP_FROM_INT_* macros do not end up referring unnecessarily to
architecture-specific state for exceptions and rounding modes when the
types in question mean the conversion is always exact, so no
initialization of that state is needed to avoid compiler warnings.

As is usual in soft-fp, this patch doesn't use "# " indentation inside
#if.  The soft-fp coding style could do with generally being cleaned
up to follow the normal glibc coding style, but I propose to deal with
that separately from substantive changes.

David, Richard: I think the SPARC and Alpha uses of soft-fp could
benefit from this.  Alpha already does something similar of its own
regarding redefining FP_ROUNDMODE, while if the relevant SPARC files
are converted then that would eliminate the last remaining uses of
FP_CLEAR_EXCEPTIONS (after my patch
<https://sourceware.org/ml/libc-alpha/2013-10/msg00348.html> for
negations), which could then be removed as an unused macro.
(FP_UNSET_EXCEPTION also appears unused.  The only uses of
FP_CLEAR_EXCEPTIONS in the Linux kernel are useless although
harmless.)

Tested for powerpc-nofpu.

2013-10-09  Joseph Myers  <joseph@codesourcery.com>

	* soft-fp/soft-fp.h [FP_NO_EXCEPTIONS] (FP_SET_EXCEPTION):
	Undefine and redefine.
	[FP_NO_EXCEPTIONS] (FP_CUR_EXCEPTIONS): Likewise.
	[FP_NO_EXCEPTIONS] (FP_TRAPPING_EXCEPTIONS): Likewise.
	[FP_NO_EXCEPTIONS] (FP_ROUNDMODE): Likewise.
	* soft-fp/floatditf.c (FP_NO_EXCEPTIONS): Define macro.
	(__floatditf): Don't use FP_DECL_EX or FP_HANDLE_EXCEPTIONS.
	* soft-fp/floatsidf.c (FP_NO_EXCEPTIONS): Define macro.
	(__floatsidf): Don't use FP_DECL_EX or FP_HANDLE_EXCEPTIONS.
	* soft-fp/floatsitf.c (FP_NO_EXCEPTIONS): Define macro.
	(__floatsitf): Don't use FP_DECL_EX or FP_HANDLE_EXCEPTIONS.
	* soft-fp/floatunditf.c (FP_NO_EXCEPTIONS): Define macro.
	(__floatunditf): Don't use FP_DECL_EX or FP_HANDLE_EXCEPTIONS.
	* soft-fp/floatunsidf.c (FP_NO_EXCEPTIONS): Define macro.
	(__floatunsidf): Don't use FP_DECL_EX or FP_HANDLE_EXCEPTIONS.
	* soft-fp/floatunsitf.c (FP_NO_EXCEPTIONS): Define macro.
	(__floatunsitf): Don't use FP_DECL_EX or FP_HANDLE_EXCEPTIONS.

diff --git a/soft-fp/floatditf.c b/soft-fp/floatditf.c
index 68da6c6..7f5e3b0 100644
--- a/soft-fp/floatditf.c
+++ b/soft-fp/floatditf.c
@@ -28,18 +28,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXCEPTIONS
 #include "soft-fp.h"
 #include "quad.h"
 
 TFtype __floatditf(DItype i)
 {
-  FP_DECL_EX;
   FP_DECL_Q(A);
   TFtype a;
 
   FP_FROM_INT_Q(A, i, DI_BITS, UDItype);
   FP_PACK_RAW_Q(a, A);
-  FP_HANDLE_EXCEPTIONS;
 
   return a;
 }
diff --git a/soft-fp/floatsidf.c b/soft-fp/floatsidf.c
index ec578fb..967a83f 100644
--- a/soft-fp/floatsidf.c
+++ b/soft-fp/floatsidf.c
@@ -28,18 +28,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXCEPTIONS
 #include "soft-fp.h"
 #include "double.h"
 
 DFtype __floatsidf(SItype i)
 {
-  FP_DECL_EX;
   FP_DECL_D(A);
   DFtype a;
 
   FP_FROM_INT_D(A, i, SI_BITS, USItype);
   FP_PACK_RAW_D(a, A);
-  FP_HANDLE_EXCEPTIONS;
 
   return a;
 }
diff --git a/soft-fp/floatsitf.c b/soft-fp/floatsitf.c
index 6e24b9e..a2c3451 100644
--- a/soft-fp/floatsitf.c
+++ b/soft-fp/floatsitf.c
@@ -28,18 +28,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXCEPTIONS
 #include "soft-fp.h"
 #include "quad.h"
 
 TFtype __floatsitf(SItype i)
 {
-  FP_DECL_EX;
   FP_DECL_Q(A);
   TFtype a;
 
   FP_FROM_INT_Q(A, i, SI_BITS, USItype);
   FP_PACK_RAW_Q(a, A);
-  FP_HANDLE_EXCEPTIONS;
 
   return a;
 }
diff --git a/soft-fp/floatunditf.c b/soft-fp/floatunditf.c
index fff73fd..e178dea 100644
--- a/soft-fp/floatunditf.c
+++ b/soft-fp/floatunditf.c
@@ -28,19 +28,18 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXCEPTIONS
 #include "soft-fp.h"
 #include "quad.h"
 
 TFtype
 __floatunditf(UDItype i)
 {
-  FP_DECL_EX;
   FP_DECL_Q(A);
   TFtype a;
 
   FP_FROM_INT_Q(A, i, DI_BITS, UDItype);
   FP_PACK_RAW_Q(a, A);
-  FP_HANDLE_EXCEPTIONS;
 
   return a;
 }
diff --git a/soft-fp/floatunsidf.c b/soft-fp/floatunsidf.c
index 548dc7c..3d9656f 100644
--- a/soft-fp/floatunsidf.c
+++ b/soft-fp/floatunsidf.c
@@ -28,18 +28,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXCEPTIONS
 #include "soft-fp.h"
 #include "double.h"
 
 DFtype __floatunsidf(USItype i)
 {
-  FP_DECL_EX;
   FP_DECL_D(A);
   DFtype a;
 
   FP_FROM_INT_D(A, i, SI_BITS, USItype);
   FP_PACK_RAW_D(a, A);
-  FP_HANDLE_EXCEPTIONS;
 
   return a;
 }
diff --git a/soft-fp/floatunsitf.c b/soft-fp/floatunsitf.c
index 1099c2e..e94ae92 100644
--- a/soft-fp/floatunsitf.c
+++ b/soft-fp/floatunsitf.c
@@ -28,19 +28,18 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXCEPTIONS
 #include "soft-fp.h"
 #include "quad.h"
 
 TFtype
 __floatunsitf(USItype i)
 {
-  FP_DECL_EX;
   FP_DECL_Q(A);
   TFtype a;
 
   FP_FROM_INT_Q(A, i, SI_BITS, USItype);
   FP_PACK_RAW_Q(a, A);
-  FP_HANDLE_EXCEPTIONS;
 
   return a;
 }
diff --git a/soft-fp/soft-fp.h b/soft-fp/soft-fp.h
index b1c6e61..b8a7ead 100644
--- a/soft-fp/soft-fp.h
+++ b/soft-fp/soft-fp.h
@@ -134,6 +134,30 @@
 #define FP_TRAPPING_EXCEPTIONS 0
 #endif
 
+/* A file using soft-fp may define FP_NO_EXCEPTIONS before including
+   soft-fp.h to indicate that, although a macro used there could raise
+   exceptions, or do rounding and potentially thereby raise
+   exceptions, for some arguments, for the particular arguments used
+   in that file no exceptions or rounding can occur.  Such a file
+   should not itself use macros relating to handling exceptions and
+   rounding modes; this is only for indirect uses (in particular, in
+   _FP_FROM_INT and the macros it calls).  */
+#ifdef FP_NO_EXCEPTIONS
+
+#undef FP_SET_EXCEPTION
+#define FP_SET_EXCEPTION(ex) do {} while (0)
+
+#undef FP_CUR_EXCEPTIONS
+#define FP_CUR_EXCEPTIONS 0
+
+#undef FP_TRAPPING_EXCEPTIONS
+#define FP_TRAPPING_EXCEPTIONS 0
+
+#undef FP_ROUNDMODE
+#define FP_ROUNDMODE FP_RND_ZERO
+
+#endif
+
 #define _FP_ROUND_NEAREST(wc, X)			\
 do {							\
     if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND)	\

-- 
Joseph S. Myers
joseph@codesourcery.com


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