This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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] Eliminate MODE_HAS_... macros


Richard Guenther wrote:

> Yes, it would make sense to change
> REAL_MODE_FORMAT_COMPOSITE_P to either take a struct real_format
> or to a different name like REAL_MODE_COMPOSITE_P.  I also still
> think that if you pass a mode it makes sense to handle non-scalar
> modes as well, likewise for checking purposes (we'd just index into
> real_format_for_mode randomly otherwise) we should check if the
> passed mode is a float mode - and if we do, we can simply be
> generous and handle non-float modes appropriately.

OK, here's a version of the patch with those changes.  Would this
be OK (once testing has completed)?

Bye,
Ulrich

ChangeLog:

	* real.h (struct real_format): New member has_sign_dependent_rounding.
	* real.c (ieee_single_format, mips_single_format, motorola_single_format,
        spu_single_format, ieee_double_format, mips_double_format,
        motorola_double_format, ieee_extended_motorola_format,
        ieee_extended_intel_96_format, ieee_extended_intel_128_format,
        ieee_extended_intel_96_round_53_format, ibm_extended_format,
        mips_extended_format, ieee_quad_format, mips_quad_format,
        vax_f_format, vax_d_format, vax_g_format): Initialize it.
        * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Likewise.

	* defaults.h (MODE_HAS_NANS, MODE_HAS_INFINITIES,
	MODE_HAS_SIGNED_ZEROS, MODE_HAS_SIGN_DEPENDENT_ROUNDING): Remove.
	* config/spu/spu.h (MODE_HAS_NANS, MODE_HAS_INFINITIES,
	MODE_HAS_SIGN_DEPENDENT_ROUNDING): Remove.
	(ROUND_TOWARDS_ZERO): Likewise.

	* real.h (REAL_MODE_FORMAT): Protect MODE against macro expansion.
	(FLOAT_MODE_FORMAT): New macro.
	(REAL_MODE_FORMAT_COMPOSITE_P): Remove, replace by ...
	(MODE_COMPOSITE_P): ... this new macro.
	(MODE_HAS_NANS, MODE_HAS_INFINITIES, MODE_HAS_SIGNED_ZEROS,
	MODE_HAS_SIGN_DEPENDENT_ROUNDING): Likewise.
	* machmode.h (GET_MODE_INNER): Cast result to enum machine_mode.

	* flags.h: Include "real.h".

	* fold-const.c (const_binop): Use MODE_COMPOSITE_P instead of
	REAL_MODE_FORMAT_COMPOSITE_P.
	* simplify-rtx.c (simplify_const_binary_operation): Likewise.

	* doc/tm.texi (Storage Layout): Remove documentation of
	MODE_HAS_NANS, MODE_HAS_INFINITIES, MODE_HAS_SIGNED_ZEROS,
	MODE_HAS_SIGN_DEPENDENT_ROUNDING.  Update documentation of
	ROUND_TOWARDS_ZERO and LARGEST_EXPONENT_IS_NORMAL to clarify
	they only apply to libgcc2.a.


diff -urNp -x .svn gcc-head-orig/gcc/config/pdp11/pdp11.c gcc-head/gcc/config/pdp11/pdp11.c
--- gcc-head-orig/gcc/config/pdp11/pdp11.c	2008-08-11 17:22:21.000000000 +0200
+++ gcc-head/gcc/config/pdp11/pdp11.c	2008-08-11 17:28:07.000000000 +0200
@@ -79,6 +79,7 @@ const struct real_format pdp11_f_format 
     false,
     false,
     false,
+    false,
     false
   };
 
@@ -99,6 +100,7 @@ const struct real_format pdp11_d_format 
     false,
     false,
     false,
+    false,
     false
   };
 
diff -urNp -x .svn gcc-head-orig/gcc/config/spu/spu.h gcc-head/gcc/config/spu/spu.h
--- gcc-head-orig/gcc/config/spu/spu.h	2008-08-11 17:22:21.000000000 +0200
+++ gcc-head/gcc/config/spu/spu.h	2008-08-11 17:28:07.000000000 +0200
@@ -124,34 +124,6 @@ extern GTY(()) int spu_tune;
 
 #define STACK_SIZE_MODE SImode
 
-/* #define TARGET_FLOAT_FORMAT     	SPU_FLOAT_FORMAT */
-
-#ifndef MODE_HAS_NANS
-#define MODE_HAS_NANS(MODE)                                     \
-  (FLOAT_MODE_P (MODE) 						\
-   && MODE != SFmode						\
-   && !LARGEST_EXPONENT_IS_NORMAL (GET_MODE_BITSIZE (MODE)))
-#endif
-                                                                              
-#ifndef MODE_HAS_INFINITIES
-#define MODE_HAS_INFINITIES(MODE)                               \
-  (FLOAT_MODE_P (MODE) 						\
-   && MODE != SFmode                                            \
-   && !LARGEST_EXPONENT_IS_NORMAL (GET_MODE_BITSIZE (MODE)))
-#endif
-                                                                              
-#ifndef MODE_HAS_SIGN_DEPENDENT_ROUNDING
-#define MODE_HAS_SIGN_DEPENDENT_ROUNDING(MODE)                  \
-  (FLOAT_MODE_P (MODE)                                          \
-    && MODE != SFmode                                           \
-   && !ROUND_TOWARDS_ZERO)
-#endif
-
-#define ROUND_TOWARDS_ZERO 1
-
-/* This is certainly true.  Should it be defined?  (It wasn't before.) */
-/* #define LARGEST_EXPONENT_IS_NORMAL(size) (size != 32) */
-
 
 /* Type Layout */
 
diff -urNp -x .svn gcc-head-orig/gcc/defaults.h gcc-head/gcc/defaults.h
--- gcc-head-orig/gcc/defaults.h	2008-08-11 17:22:21.000000000 +0200
+++ gcc-head/gcc/defaults.h	2008-08-11 17:28:07.000000000 +0200
@@ -681,32 +681,6 @@ along with GCC; see the file COPYING3.  
 #define ROUND_TOWARDS_ZERO 0
 #endif
 
-#ifndef MODE_HAS_NANS
-#define MODE_HAS_NANS(MODE)					\
-  (FLOAT_MODE_P (MODE)						\
-   && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT			\
-   && !LARGEST_EXPONENT_IS_NORMAL (GET_MODE_BITSIZE (MODE)))
-#endif
-
-#ifndef MODE_HAS_INFINITIES
-#define MODE_HAS_INFINITIES(MODE)				\
-  (FLOAT_MODE_P (MODE)						\
-   && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT			\
-   && !LARGEST_EXPONENT_IS_NORMAL (GET_MODE_BITSIZE (MODE)))
-#endif
-
-#ifndef MODE_HAS_SIGNED_ZEROS
-#define MODE_HAS_SIGNED_ZEROS(MODE) \
-  (FLOAT_MODE_P (MODE) && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
-#endif
-
-#ifndef MODE_HAS_SIGN_DEPENDENT_ROUNDING
-#define MODE_HAS_SIGN_DEPENDENT_ROUNDING(MODE)			\
-  (FLOAT_MODE_P (MODE)						\
-   && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT			\
-   && !ROUND_TOWARDS_ZERO)
-#endif
-
 #ifndef FLOAT_LIB_COMPARE_RETURNS_BOOL
 #define FLOAT_LIB_COMPARE_RETURNS_BOOL(MODE, COMPARISON) false
 #endif
diff -urNp -x .svn gcc-head-orig/gcc/doc/tm.texi gcc-head/gcc/doc/tm.texi
--- gcc-head-orig/gcc/doc/tm.texi	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/doc/tm.texi	2008-08-11 17:28:08.000000000 +0200
@@ -1407,78 +1407,12 @@ The ordering of the component words of f
 memory is controlled by @code{FLOAT_WORDS_BIG_ENDIAN}.
 @end defmac
 
-@defmac MODE_HAS_NANS (@var{mode})
-When defined, this macro should be true if @var{mode} has a NaN
-representation.  The compiler assumes that NaNs are not equal to
-anything (including themselves) and that addition, subtraction,
-multiplication and division all return NaNs when one operand is
-NaN@.
-
-By default, this macro is true if @var{mode} is a floating-point
-mode and the target floating-point format is IEEE@.
-@end defmac
-
-@defmac MODE_HAS_INFINITIES (@var{mode})
-This macro should be true if @var{mode} can represent infinity.  At
-present, the compiler uses this macro to decide whether @samp{x - x}
-is always defined.  By default, the macro is true when @var{mode}
-is a floating-point mode and the target format is IEEE@.
-@end defmac
-
-@defmac MODE_HAS_SIGNED_ZEROS (@var{mode})
-True if @var{mode} distinguishes between positive and negative zero.
-The rules are expected to follow the IEEE standard:
-
-@itemize @bullet
-@item
-@samp{x + x} has the same sign as @samp{x}.
-
-@item
-If the sum of two values with opposite sign is zero, the result is
-positive for all rounding modes expect towards @minus{}infinity, for
-which it is negative.
-
-@item
-The sign of a product or quotient is negative when exactly one
-of the operands is negative.
-@end itemize
-
-The default definition is true if @var{mode} is a floating-point
-mode and the target format is IEEE@.
-@end defmac
-
-@defmac MODE_HAS_SIGN_DEPENDENT_ROUNDING (@var{mode})
-If defined, this macro should be true for @var{mode} if it has at
-least one rounding mode in which @samp{x} and @samp{-x} can be
-rounded to numbers of different magnitude.  Two such modes are
-towards @minus{}infinity and towards +infinity.
-
-The default definition of this macro is true if @var{mode} is
-a floating-point mode and the target format is IEEE@.
-@end defmac
-
 @defmac ROUND_TOWARDS_ZERO
 If defined, this macro should be true if the prevailing rounding
-mode is towards zero.  A true value has the following effects:
-
-@itemize @bullet
-@item
-@code{MODE_HAS_SIGN_DEPENDENT_ROUNDING} will be false for all modes.
+mode is towards zero.
 
-@item
-@file{libgcc.a}'s floating-point emulator will round towards zero
-rather than towards nearest.
-
-@item
-The compiler's floating-point emulator will round towards zero after
-doing arithmetic, and when converting from the internal float format to
-the target format.
-@end itemize
-
-The macro does not affect the parsing of string literals.  When the
-primary rounding mode is towards zero, library functions like
-@code{strtod} might still round towards nearest, and the compiler's
-parser should behave like the target's @code{strtod} where possible.
+Defining this macro only affects the way @file{libgcc.a} emulates
+floating-point arithmetic.
 
 Not defining this macro is equivalent to returning zero.
 @end defmac
@@ -1488,9 +1422,7 @@ This macro should return true if floats 
 bits do not have a NaN or infinity representation, but use the largest
 exponent for normal numbers instead.
 
-Defining this macro to true for @var{size} causes @code{MODE_HAS_NANS}
-and @code{MODE_HAS_INFINITIES} to be false for @var{size}-bit modes.
-It also affects the way @file{libgcc.a} and @file{real.c} emulate
+Defining this macro only affects the way @file{libgcc.a} emulates
 floating-point arithmetic.
 
 The default definition of this macro returns false for all sizes.
diff -urNp -x .svn gcc-head-orig/gcc/flags.h gcc-head/gcc/flags.h
--- gcc-head-orig/gcc/flags.h	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/flags.h	2008-08-11 17:28:08.000000000 +0200
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  
 
 #include "coretypes.h"
 #include "options.h"
+#include "real.h"
 
 enum debug_info_type
 {
diff -urNp -x .svn gcc-head-orig/gcc/fold-const.c gcc-head/gcc/fold-const.c
--- gcc-head-orig/gcc/fold-const.c	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/fold-const.c	2008-08-11 17:38:45.000000000 +0200
@@ -1885,8 +1885,7 @@ const_binop (enum tree_code code, tree a
 	 flag_rounding_math is set, or if GCC's software emulation
 	 is unable to accurately represent the result.  */
       if ((flag_rounding_math
-	   || (REAL_MODE_FORMAT_COMPOSITE_P (mode)
-	       && !flag_unsafe_math_optimizations))
+	   || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
 	  && (inexact || !real_identical (&result, &value)))
 	return NULL_TREE;
 
diff -urNp -x .svn gcc-head-orig/gcc/machmode.h gcc-head/gcc/machmode.h
--- gcc-head-orig/gcc/machmode.h	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/machmode.h	2008-08-11 17:28:08.000000000 +0200
@@ -202,7 +202,7 @@ extern const unsigned HOST_WIDE_INT mode
 /* Return the mode of the inner elements in a vector.  */
 
 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
-#define GET_MODE_INNER(MODE) mode_inner[MODE]
+#define GET_MODE_INNER(MODE) ((enum machine_mode) mode_inner[MODE])
 
 /* Get the size in bytes of the basic parts of an object of mode MODE.  */
 
diff -urNp -x .svn gcc-head-orig/gcc/real.c gcc-head/gcc/real.c
--- gcc-head-orig/gcc/real.c	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/real.c	2008-08-11 17:28:08.000000000 +0200
@@ -2871,6 +2871,7 @@ const struct real_format ieee_single_for
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -2890,6 +2891,7 @@ const struct real_format mips_single_for
     true,
     true,
     true,
+    true,
     false,
     true
   };
@@ -2911,6 +2913,7 @@ const struct real_format motorola_single
     true,
     true,
     true,
+    true,
     true
   };
 
@@ -2939,6 +2942,7 @@ const struct real_format spu_single_form
     true,
     false,
     false,
+    false,
     true,
     true,
     false,
@@ -3150,6 +3154,7 @@ const struct real_format ieee_double_for
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -3169,6 +3174,7 @@ const struct real_format mips_double_for
     true,
     true,
     true,
+    true,
     false,
     true
   };
@@ -3190,6 +3196,7 @@ const struct real_format motorola_double
     true,
     true,
     true,
+    true,
     true
   };
 
@@ -3528,6 +3535,7 @@ const struct real_format ieee_extended_m
     true,
     true,
     true,
+    true,
     true
   };
 
@@ -3548,6 +3556,7 @@ const struct real_format ieee_extended_i
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -3568,6 +3577,7 @@ const struct real_format ieee_extended_i
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -3590,6 +3600,7 @@ const struct real_format ieee_extended_i
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -3677,6 +3688,7 @@ const struct real_format ibm_extended_fo
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -3696,6 +3708,7 @@ const struct real_format mips_extended_f
     true,
     true,
     true,
+    true,
     false,
     true
   };
@@ -3959,6 +3972,7 @@ const struct real_format ieee_quad_forma
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -3978,6 +3992,7 @@ const struct real_format mips_quad_forma
     true,
     true,
     true,
+    true,
     false,
     true
   };
@@ -4278,6 +4293,7 @@ const struct real_format vax_f_format =
     false,
     false,
     false,
+    false,
     false
   };
 
@@ -4298,6 +4314,7 @@ const struct real_format vax_d_format =
     false,
     false,
     false,
+    false,
     false
   };
 
@@ -4318,6 +4335,7 @@ const struct real_format vax_g_format =
     false,
     false,
     false,
+    false,
     false
   };
 
@@ -4391,6 +4409,7 @@ const struct real_format decimal_single_
     true,
     true,
     true,
+    true,
     true, 
     true,
     false
@@ -4414,6 +4433,7 @@ const struct real_format decimal_double_
     true,
     true,
     true,
+    true,
     false
   };
 
@@ -4432,6 +4452,7 @@ const struct real_format decimal_quad_fo
     false,
     true,
     true,
+    true,
     true, 
     true, 
     true,
@@ -4474,6 +4495,7 @@ const struct real_format real_internal_f
     -1,
     -1,
     false,
+    false,
     true,
     true,
     false,
diff -urNp -x .svn gcc-head-orig/gcc/real.h gcc-head/gcc/real.h
--- gcc-head-orig/gcc/real.h	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/real.h	2008-08-11 17:38:12.000000000 +0200
@@ -149,6 +149,7 @@ struct real_format
 
   /* Default rounding mode for operations on this format.  */
   bool round_towards_zero;
+  bool has_sign_dependent_rounding;
 
   /* Properties of the format.  */
   bool has_nans;
@@ -171,15 +172,32 @@ extern const struct real_format *
 
 #define REAL_MODE_FORMAT(MODE)						\
   (real_format_for_mode[DECIMAL_FLOAT_MODE_P (MODE)			\
-			? ((MODE - MIN_MODE_DECIMAL_FLOAT)		\
+			? (((MODE) - MIN_MODE_DECIMAL_FLOAT)		\
 			   + (MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1))	\
-			: (MODE - MIN_MODE_FLOAT)])
+			: ((MODE) - MIN_MODE_FLOAT)])
+
+#define FLOAT_MODE_FORMAT(MODE) \
+  (REAL_MODE_FORMAT (SCALAR_FLOAT_MODE_P (MODE)? (MODE) \
+					       : GET_MODE_INNER (MODE)))
 
 /* The following macro determines whether the floating point format is
    composite, i.e. may contain non-consecutive mantissa bits, in which
    case compile-time FP overflow may not model run-time overflow.  */
-#define REAL_MODE_FORMAT_COMPOSITE_P(MODE) \
-	((REAL_MODE_FORMAT(MODE))->pnan < (REAL_MODE_FORMAT (MODE))->p)
+#define MODE_COMPOSITE_P(MODE) \
+  (FLOAT_MODE_P (MODE) \
+   && FLOAT_MODE_FORMAT (MODE)->pnan < FLOAT_MODE_FORMAT (MODE)->p)
+
+/* Accessor macros for format properties.  */
+#define MODE_HAS_NANS(MODE) \
+  (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_nans)
+#define MODE_HAS_INFINITIES(MODE) \
+  (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_inf)
+#define MODE_HAS_SIGNED_ZEROS(MODE) \
+  (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_signed_zero)
+#define MODE_HAS_SIGN_DEPENDENT_ROUNDING(MODE) \
+  (FLOAT_MODE_P (MODE) \
+   && FLOAT_MODE_FORMAT (MODE)->has_sign_dependent_rounding)
+
 
 /* Declare functions in real.c.  */
 
diff -urNp -x .svn gcc-head-orig/gcc/simplify-rtx.c gcc-head/gcc/simplify-rtx.c
--- gcc-head-orig/gcc/simplify-rtx.c	2008-08-11 17:22:22.000000000 +0200
+++ gcc-head/gcc/simplify-rtx.c	2008-08-11 17:39:03.000000000 +0200
@@ -3080,8 +3080,7 @@ simplify_const_binary_operation (enum rt
 	     is unable to accurately represent the result.  */
 
 	  if ((flag_rounding_math
-	       || (REAL_MODE_FORMAT_COMPOSITE_P (mode)
-		   && !flag_unsafe_math_optimizations))
+	       || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
 	      && (inexact || !real_identical (&result, &value)))
 	    return NULL_RTX;
 


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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