OSDN Git Service

2007-01-24 Andreas Tobler <a.tobler@schweiz.org>
[pf3gnuchains/gcc-fork.git] / gcc / dfp.c
index 55c6f2d..b388f93 100644 (file)
--- a/gcc/dfp.c
+++ b/gcc/dfp.c
@@ -1,5 +1,5 @@
 /* Decimal floating point support.
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -36,13 +36,13 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #include "decimal32.h"
 #include "decNumber.h"
 
-static unsigned long
-dfp_byte_swap (unsigned long in)
+static uint32_t
+dfp_byte_swap (uint32_t in)
 {
-  unsigned long out;
+  uint32_t out = 0;
   unsigned char *p = (unsigned char *) &out;
   union {
-    unsigned long i;
+    uint32_t i;
     unsigned char b[4];
   } u;
 
@@ -137,12 +137,12 @@ decimal_to_decnumber (const REAL_VALUE_TYPE *r, decNumber *dn)
 
   /* Fix up sign bit.  */
   if (r->sign != decNumberIsNegative (dn))
-    decNumberNegate (dn);
+    dn->bits ^= DECNEG;
 }
 
 /* Encode a real into an IEEE 754R decimal32 type.  */
 
-void 
+void
 encode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
                  long *buf, const REAL_VALUE_TYPE *r)
 {
@@ -164,8 +164,9 @@ encode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
 
 /* Decode an IEEE 754R decimal32 type into a real.  */
 
-void decode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
-                      REAL_VALUE_TYPE *r, const long *buf)
+void
+decode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
+                 REAL_VALUE_TYPE *r, const long *buf)
 {
   decNumber dn;
   decimal32 d32;
@@ -185,7 +186,7 @@ void decode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
 
 /* Encode a real into an IEEE 754R decimal64 type.  */
 
-void 
+void
 encode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
                  long *buf, const REAL_VALUE_TYPE *r)
 {
@@ -213,7 +214,7 @@ encode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
 
 /* Decode an IEEE 754R decimal64 type into a real.  */
 
-void 
+void
 decode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
                  REAL_VALUE_TYPE *r, const long *buf)
 { 
@@ -241,7 +242,7 @@ decode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
 
 /* Encode a real into an IEEE 754R decimal128 type.  */
 
-void 
+void
 encode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
                   long *buf, const REAL_VALUE_TYPE *r)
 {
@@ -273,7 +274,7 @@ encode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
 
 /* Decode an IEEE 754R decimal128 type into a real.  */
 
-void 
+void
 decode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
                   REAL_VALUE_TYPE *r, const long *buf)
 {
@@ -444,10 +445,11 @@ decimal_real_convert (REAL_VALUE_TYPE *r, enum machine_mode mode,
    CROP_TRAILING_ZEROS, strip trailing zeros.  Currently, not honoring
    DIGITS or CROP_TRAILING_ZEROS.  */
 
-void decimal_real_to_decimal (char *str, const REAL_VALUE_TYPE *r_orig,
-                             size_t buf_size,
-                             size_t digits ATTRIBUTE_UNUSED,
-                             int crop_trailing_zeros ATTRIBUTE_UNUSED)
+void
+decimal_real_to_decimal (char *str, const REAL_VALUE_TYPE *r_orig,
+                        size_t buf_size,
+                        size_t digits ATTRIBUTE_UNUSED,
+                        int crop_trailing_zeros ATTRIBUTE_UNUSED)
 {
   decimal128 *d128 = (decimal128*) r_orig->sig;
 
@@ -597,49 +599,42 @@ decimal_real_to_integer2 (HOST_WIDE_INT *plow, HOST_WIDE_INT *phigh,
   real_to_integer2 (plow, phigh, &to);
 }
 
-/* Perform the decimal floating point operation described by COODE.
-   For a unary operation, leave OP1 NULL.  This function returns true
-   if the result may be inexact due to loss of precision.  */
+/* Perform the decimal floating point operation described by CODE.
+   For a unary operation, OP1 will be NULL.  This function returns
+   true if the result may be inexact due to loss of precision.  */
 
 bool
-decimal_real_arithmetic (REAL_VALUE_TYPE *r, int icode,
+decimal_real_arithmetic (REAL_VALUE_TYPE *r, enum tree_code code,
                         const REAL_VALUE_TYPE *op0,
                         const REAL_VALUE_TYPE *op1)
 {
-  enum tree_code code = icode;
-  REAL_VALUE_TYPE a1;
-  REAL_VALUE_TYPE b1;
+  REAL_VALUE_TYPE a, b;
 
-  /* If either op is not a decimal, create a temporary decimal
-     versions.  */
+  /* If either operand is non-decimal, create temporaries.  */
   if (!op0->decimal)
     {
-      decimal_from_binary (&a1, op0);
-      op0 = &a1;
+      decimal_from_binary (&a, op0);
+      op0 = &a;
     }
   if (op1 && !op1->decimal)
     {
-      decimal_from_binary (&b1, op1);
-      op1 = &b1;
+      decimal_from_binary (&b, op1);
+      op1 = &b;
     }
 
   switch (code)
     {
     case PLUS_EXPR:
-      (void) decimal_do_add (r, op0, op1, 0);
-      break;
+      return decimal_do_add (r, op0, op1, 0);
 
     case MINUS_EXPR:
-      (void) decimal_do_add (r, op0, op1, 1);
-      break;
+      return decimal_do_add (r, op0, op1, 1);
 
     case MULT_EXPR:
-      (void) decimal_do_multiply (r, op0, op1);
-      break;
+      return decimal_do_multiply (r, op0, op1);
 
     case RDIV_EXPR:
-      (void) decimal_do_divide (r, op0, op1);
-      break;
+      return decimal_do_divide (r, op0, op1);
 
     case MIN_EXPR:
       if (op1->cl == rvc_nan)
@@ -648,7 +643,7 @@ decimal_real_arithmetic (REAL_VALUE_TYPE *r, int icode,
         *r = *op0;
       else
         *r = *op1;
-      break;
+      return false;
 
     case MAX_EXPR:
       if (op1->cl == rvc_nan)
@@ -657,7 +652,7 @@ decimal_real_arithmetic (REAL_VALUE_TYPE *r, int icode,
         *r = *op1;
       else
         *r = *op0;
-      break;
+      return false;
 
     case NEGATE_EXPR:
       {
@@ -669,7 +664,7 @@ decimal_real_arithmetic (REAL_VALUE_TYPE *r, int icode,
        /* Keep sign field in sync.  */
        r->sign ^= 1;
       }
-      break;
+      return false;
 
     case ABS_EXPR:
       {
@@ -681,19 +676,15 @@ decimal_real_arithmetic (REAL_VALUE_TYPE *r, int icode,
        /* Keep sign field in sync.  */
        r->sign = 0;
       }
-      break;
+      return false;
 
     case FIX_TRUNC_EXPR:
       decimal_do_fix_trunc (r, op0);
-      break;
+      return false;
 
     default:
       gcc_unreachable ();
     }
-
-  /* FIXME: Indicate all operations as inexact for now due to unknown
-     working precision.  */
-  return true;
 }
 
 /* Fills R with the largest finite value representable in mode MODE.