real.c (real_sqrt): Return a bool result indicating whether a floating point exceptio...
authorRoger Sayle <roger@eyesopen.com>
Wed, 15 Jan 2003 17:40:26 +0000 (17:40 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Wed, 15 Jan 2003 17:40:26 +0000 (17:40 +0000)
* real.c (real_sqrt): Return a bool result indicating whether
a floating point exception or trap should be raised.
* real.h (real_sqrt): Update function prototype.
* builtins.c (fold_builtin): Only fold non-trapping square
roots unless we're ignoring errno and trapping math.

From-SVN: r61337

gcc/ChangeLog
gcc/builtins.c
gcc/real.c
gcc/real.h

index 7d82871b602e8cac5ba9328cdc0a418f03c5709d..503ad571ad7a61cf12518215d594d90224b12482 100644 (file)
@@ -1,3 +1,11 @@
+2003-01-15  Roger Sayle  <roger@eyesopen.com>
+
+       * real.c (real_sqrt): Return a bool result indicating whether
+       a floating point exception or trap should be raised.
+       * real.h (real_sqrt): Update function prototype.
+       * builtins.c (fold_builtin): Only fold non-trapping square
+       roots unless we're ignoring errno and trapping math.
+
 2003-01-15  John David Anglin  <dave.anglin@nrc.gc.ca>
 
        * expr.h (emit_conditional_add): Add PARAMS to declaration.
index 7c9d999979e62a6dc9b6180320e8a1783d89afb4..ffa09f9453e14f66e2c58413c4af787d270dace9 100644 (file)
@@ -1,6 +1,6 @@
 /* Expand builtin functions.
-   Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -4308,11 +4308,9 @@ fold_builtin (exp)
 
              x = TREE_REAL_CST (arg);
              mode = TYPE_MODE (TREE_TYPE (arg));
-             if (!HONOR_SNANS (mode) || !real_isnan (&x))
-             {
-               real_sqrt (&r, mode, &x);
+             if (real_sqrt (&r, mode, &x)
+                 || (!flag_trapping_math && !flag_errno_math))
                return build_real (TREE_TYPE (arg), r);
-             }
            }
 
          /* Optimize sqrt(exp(x)) = exp(x/2.0).  */
index 7d7b4bb16377138bfc03e67cd56014eea7347087..f1e10b33ac5e9878e3080d6deec8b2669ff25231 100644 (file)
@@ -1,6 +1,6 @@
 /* real.c - software floating point emulation.
-   Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2002, 2003 Free Software Foundation, Inc.
    Contributed by Stephen L. Moshier (moshier@world.std.com).
    Re-written by Richard Henderson  <rth@redhat.com>
 
@@ -4401,11 +4401,12 @@ const struct real_format *real_format_for_mode[TFmode - QFmode + 1] =
 
 \f
 /* Calculate the square root of X in mode MODE, and store the result
-   in R.  For details see "High Precision Division and Square Root",
+   in R.  Return TRUE if the operation does not raise an exception.
+   For details see "High Precision Division and Square Root",
    Alan H. Karp and Peter Markstein, HP Lab Report 93-93-42, June
    1993.  http://www.hpl.hp.com/techreports/93/HPL-93-42.pdf.  */
 
-void
+bool
 real_sqrt (r, mode, x)
      REAL_VALUE_TYPE *r;
      enum machine_mode mode;
@@ -4421,7 +4422,7 @@ real_sqrt (r, mode, x)
   if (real_isnegzero (x))
     {
       *r = *x;
-      return;
+      return false;
     }
 
   /* Negative arguments return NaN.  */
@@ -4429,14 +4430,14 @@ real_sqrt (r, mode, x)
     {
       /* Mode is ignored for canonical NaN.  */
       real_nan (r, "", 1, SFmode);
-      return;
+      return false;
     }
 
   /* Infinity and NaN return themselves.  */
   if (real_isinf (x) || real_isnan (x))
     {
       *r = *x;
-      return;
+      return false;
     }
 
   if (!init)
@@ -4479,5 +4480,6 @@ real_sqrt (r, mode, x)
   /* ??? We need a Tuckerman test to get the last bit.  */
 
   real_convert (r, mode, &h);
+  return true;
 }
 
index 163c283c1719ad03cd2a62ea85a40b3f94ea7469..0055106555515c82cd61871226332db773029bc1 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions of floating-point access for GNU compiler.
-   Copyright (C) 1989, 1991, 1994, 1996, 1997, 1998,
-   1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1989, 1991, 1994, 1996, 1997, 1998, 1999,
+   2000, 2002, 2003 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -350,7 +350,7 @@ extern bool exact_real_inverse      PARAMS ((enum machine_mode, REAL_VALUE_TYPE *));
 extern tree build_real                 PARAMS ((tree, REAL_VALUE_TYPE));
 
 /* Calculate R as the square root of X in the given machine mode.  */
-extern void real_sqrt                  PARAMS ((REAL_VALUE_TYPE *,
+extern bool real_sqrt                  PARAMS ((REAL_VALUE_TYPE *,
                                                 enum machine_mode,
                                                 const REAL_VALUE_TYPE *));