real.c (do_fix_trunc): New.
authorRichard Henderson <rth@redhat.com>
Tue, 17 Sep 2002 02:02:08 +0000 (19:02 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Tue, 17 Sep 2002 02:02:08 +0000 (19:02 -0700)
        * real.c (do_fix_trunc): New.
        (real_arithmetic): Call it.
        * simplify-rtx.c (simplify_unary_operation): Handle FIX
        with a floating-point result mode.

From-SVN: r57223

gcc/ChangeLog
gcc/real.c
gcc/simplify-rtx.c

index 85a32f95b38cfe808681ead441a121aa0681d99b..06a2ff9966ce95f1afc27c14c995a1813d9613a9 100644 (file)
@@ -1,3 +1,10 @@
+2002-09-16  Richard Henderson  <rth@redhat.com>
+
+       * real.c (do_fix_trunc): New.
+       (real_arithmetic): Call it.
+       * simplify-rtx.c (simplify_unary_operation): Handle FIX
+       with a floating-point result mode.
+
 2002-09-16  Richard Henderson  <rth@redhat.com>
 
        * builtin-types.def (BT_FN_FLOAT_CONST_STRING): New.
index 5859f0ff87807522975d50f85774c9be311453ba..dd9f9be4f9888536522d4f8047e612a7760a4ad0 100644 (file)
@@ -174,6 +174,8 @@ static void do_divide PARAMS ((struct real_value *, const struct real_value *,
                               const struct real_value *));
 static int do_compare PARAMS ((const struct real_value *,
                               const struct real_value *, int));
+static void do_fix_trunc PARAMS ((struct real_value *,
+                                 const struct real_value *));
 
 static const struct real_value * ten_to_ptwo PARAMS ((int));
 static const struct real_value * real_digit PARAMS ((int));
@@ -1013,6 +1015,34 @@ do_compare (a, b, nan_result)
   return (a->sign ? -ret : ret);
 }
 
+/* Return A truncated to an integral value toward zero.  */
+
+void
+do_fix_trunc (r, a)
+     struct real_value *r;
+     const struct real_value *a;
+{
+  *r = *a;
+
+  switch (a->class)
+    {
+    case rvc_zero:
+    case rvc_inf:
+    case rvc_nan:
+      break;
+
+    case rvc_normal:
+      if (r->exp <= 0)
+       get_zero (r, r->sign);
+      else if (r->exp < SIGNIFICAND_BITS)
+       clear_significand_below (r, SIGNIFICAND_BITS - r->exp);
+      break;
+
+    default:
+      abort ();
+    }
+}
+
 /* Perform the binary or unary operation described by CODE.
    For a unary operation, leave OP1 NULL.  */
 
@@ -1073,6 +1103,10 @@ real_arithmetic (tr, icode, top0, top1)
       r->sign = 0;
       break;
 
+    case FIX_TRUNC_EXPR:
+      do_fix_trunc (r, op0);
+      break;
+
     default:
       abort ();
     }
index 555646cccd569fa61dd783a014412ef46cc5ab4e..3566d106a72eb74aa012bc03c2bee05e09334b69 100644 (file)
@@ -599,10 +599,22 @@ simplify_unary_operation (code, mode, op, op_mode)
          /* We don't attempt to optimize this.  */
          return 0;
 
-       case ABS:             d = REAL_VALUE_ABS (d);                   break;
-       case NEG:             d = REAL_VALUE_NEGATE (d);                break;
-       case FLOAT_TRUNCATE:  d = real_value_truncate (mode, d);        break;
-       case FLOAT_EXTEND:    /* All this does is change the mode.  */  break;
+       case ABS:
+         d = REAL_VALUE_ABS (d);
+         break;
+       case NEG:
+         d = REAL_VALUE_NEGATE (d);
+         break;
+       case FLOAT_TRUNCATE:
+         d = real_value_truncate (mode, d);
+         break;
+       case FLOAT_EXTEND:
+         /* All this does is change the mode.  */
+         break;
+       case FIX:
+         real_arithmetic (&d, FIX_TRUNC_EXPR, &d, NULL);
+         break;
+
        default:
          abort ();
        }