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: rs6000 LDBL_MAX converts to infinity


On Wed, Mar 03, 2004 at 01:53:09PM -0800, Geoff Keating wrote:
> I believe that the answer to this particular one is to change
> LDBL_MAX; it should always be the case that the high part is the sum
> of the high and low parts in round-to-nearest mode.

The value I'm using here is 0x1.fffffffffffff7ffffffffffff8p1023
converted to decimal exactly as builtin_define_float_constants does.
It's slightly different to the value reported by Richard for SGI's
float.h.  I did check that it converts back to sensible asm.  :)

	* config/rs6000/rs6000-c.c (rs6000_cpu_cpp_builtins): Set __LDBL_MAX__.
	* real.c (encode_ibm_extended): Don't bother rounding low double.

Index: gcc/config/rs6000/rs6000-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000-c.c,v
retrieving revision 1.12
diff -u -p -r1.12 rs6000-c.c
--- gcc/config/rs6000/rs6000-c.c	23 Feb 2004 17:02:51 -0000	1.12
+++ gcc/config/rs6000/rs6000-c.c	4 Mar 2004 05:47:09 -0000
@@ -75,6 +75,7 @@ rs6000_pragma_longcall (cpp_reader *pfil
    policy, rather than trying to guess what flags a user might want a
    #define for, it's better to define a flag for everything.  */
 
+#define builtin_undef(TXT) cpp_undef (pfile, TXT)
 #define builtin_define(TXT) cpp_define (pfile, TXT)
 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
 
@@ -113,7 +114,18 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfi
   RS6000_CPU_CPP_ENDIAN_BUILTINS();
 
   if (TARGET_LONG_DOUBLE_128)
-    builtin_define ("__LONG_DOUBLE_128__");
+    {
+      /* IBM extended double format is made up of two IEEE doubles.  The
+	 value of the long double is the sum of the values of the two
+	 parts.  The most significant part is required to be the value
+	 of the long double rounded to the nearest double.
+	 Rounding means we need a slightly smaller value for LDBL_MAX
+	 than that calculated in builtin_define_float_constants.  We
+	 use 0x1.fffffffffffff7ffffffffffff8p1023.  */
+      builtin_undef ("__LDBL_MAX__");
+      builtin_define ("__LDBL_MAX__=1.79769313486231580793728971405301e+308L");
+      builtin_define ("__LONG_DOUBLE_128__");
+    }
 
   switch (rs6000_current_abi)
     {
Index: gcc/real.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/real.c,v
retrieving revision 1.138
diff -u -p -r1.138 real.c
--- gcc/real.c	10 Feb 2004 23:05:58 -0000	1.138
+++ gcc/real.c	4 Mar 2004 05:55:54 -0000
@@ -3248,7 +3248,6 @@ encode_ibm_extended (const struct real_f
   if (u.class == rvc_normal)
     {
       do_add (&v, &normr, &u, 1);
-      round_for_format (base_fmt, &v);
       encode_ieee_double (base_fmt, &buf[2], &v);
     }
   else

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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