OSDN Git Service

* ggc.h (GGC_RESIZEVAR): New, reorder macros.
[pf3gnuchains/gcc-fork.git] / gcc / dfp.c
index 88ffded..0485430 100644 (file)
--- a/gcc/dfp.c
+++ b/gcc/dfp.c
@@ -1,5 +1,5 @@
 /* Decimal floating point support.
-   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -36,6 +36,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "decimal32.h"
 #include "decNumber.h"
 
+#ifndef WORDS_BIGENDIAN
+#define WORDS_BIGENDIAN 0
+#endif
+
 /* Initialize R (a real with the decimal flag set) from DN.  Can
    utilize status passed in via CONTEXT, if a previous operation had
    interesting status.  */
@@ -46,8 +50,6 @@ decimal_from_decnumber (REAL_VALUE_TYPE *r, decNumber *dn, decContext *context)
   memset (r, 0, sizeof (REAL_VALUE_TYPE));
 
   r->cl = rvc_normal;
-  if (decNumberIsZero (dn))
-    r->cl = rvc_zero;
   if (decNumberIsNaN (dn))
     r->cl = rvc_nan;
   if (decNumberIsInfinite (dn))
@@ -121,7 +123,7 @@ decimal_to_decnumber (const REAL_VALUE_TYPE *r, decNumber *dn)
     dn->bits ^= DECNEG;
 }
 
-/* Encode a real into an IEEE 754R decimal32 type.  */
+/* Encode a real into an IEEE 754 decimal32 type.  */
 
 void
 encode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
@@ -140,7 +142,7 @@ encode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
   buf[0] = *(uint32_t *) d32.bytes;
 }
 
-/* Decode an IEEE 754R decimal32 type into a real.  */
+/* Decode an IEEE 754 decimal32 type into a real.  */
 
 void
 decode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
@@ -159,7 +161,7 @@ decode_decimal32 (const struct real_format *fmt ATTRIBUTE_UNUSED,
   decimal_from_decnumber (r, &dn, &set); 
 }
 
-/* Encode a real into an IEEE 754R decimal64 type.  */
+/* Encode a real into an IEEE 754 decimal64 type.  */
 
 void
 encode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
@@ -175,11 +177,19 @@ encode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
   decimal_to_decnumber (r, &dn);
   decimal64FromNumber (&d64, &dn, &set);
 
-  buf[0] = *(uint32_t *) &d64.bytes[0];
-  buf[1] = *(uint32_t *) &d64.bytes[4];
+  if (WORDS_BIGENDIAN == FLOAT_WORDS_BIG_ENDIAN)
+    {
+      buf[0] = *(uint32_t *) &d64.bytes[0];
+      buf[1] = *(uint32_t *) &d64.bytes[4];
+    }
+  else
+    {
+      buf[0] = *(uint32_t *) &d64.bytes[4];
+      buf[1] = *(uint32_t *) &d64.bytes[0];
+    }
 }
 
-/* Decode an IEEE 754R decimal64 type into a real.  */
+/* Decode an IEEE 754 decimal64 type into a real.  */
 
 void
 decode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
@@ -192,14 +202,22 @@ decode_decimal64 (const struct real_format *fmt ATTRIBUTE_UNUSED,
   decContextDefault (&set, DEC_INIT_DECIMAL128);
   set.traps = 0;
 
-  *((uint32_t *) &d64.bytes[0]) = (uint32_t) buf[0];
-  *((uint32_t *) &d64.bytes[4]) = (uint32_t) buf[1];
+  if (WORDS_BIGENDIAN == FLOAT_WORDS_BIG_ENDIAN)
+    {
+      *((uint32_t *) &d64.bytes[0]) = (uint32_t) buf[0];
+      *((uint32_t *) &d64.bytes[4]) = (uint32_t) buf[1];
+    }
+  else
+    {
+      *((uint32_t *) &d64.bytes[0]) = (uint32_t) buf[1];
+      *((uint32_t *) &d64.bytes[4]) = (uint32_t) buf[0];
+    }
 
   decimal64ToNumber (&d64, &dn);
   decimal_from_decnumber (r, &dn, &set); 
 }
 
-/* Encode a real into an IEEE 754R decimal128 type.  */
+/* Encode a real into an IEEE 754 decimal128 type.  */
 
 void
 encode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
@@ -215,13 +233,23 @@ encode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
   decimal_to_decnumber (r, &dn);
   decimal128FromNumber (&d128, &dn, &set);
 
-  buf[0] = *(uint32_t *) &d128.bytes[0];
-  buf[1] = *(uint32_t *) &d128.bytes[4];
-  buf[2] = *(uint32_t *) &d128.bytes[8];
-  buf[3] = *(uint32_t *) &d128.bytes[12];
+  if (WORDS_BIGENDIAN == FLOAT_WORDS_BIG_ENDIAN)
+    {
+      buf[0] = *(uint32_t *) &d128.bytes[0];
+      buf[1] = *(uint32_t *) &d128.bytes[4];
+      buf[2] = *(uint32_t *) &d128.bytes[8];
+      buf[3] = *(uint32_t *) &d128.bytes[12];
+    }
+  else
+    {
+      buf[0] = *(uint32_t *) &d128.bytes[12];
+      buf[1] = *(uint32_t *) &d128.bytes[8];
+      buf[2] = *(uint32_t *) &d128.bytes[4];
+      buf[3] = *(uint32_t *) &d128.bytes[0];
+    }
 }
 
-/* Decode an IEEE 754R decimal128 type into a real.  */
+/* Decode an IEEE 754 decimal128 type into a real.  */
 
 void
 decode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
@@ -234,10 +262,20 @@ decode_decimal128 (const struct real_format *fmt ATTRIBUTE_UNUSED,
   decContextDefault (&set, DEC_INIT_DECIMAL128);
   set.traps = 0;
 
-  *((uint32_t *) &d128.bytes[0])  = (uint32_t) buf[0];
-  *((uint32_t *) &d128.bytes[4])  = (uint32_t) buf[1];
-  *((uint32_t *) &d128.bytes[8])  = (uint32_t) buf[2];
-  *((uint32_t *) &d128.bytes[12]) = (uint32_t) buf[3];
+  if (WORDS_BIGENDIAN == FLOAT_WORDS_BIG_ENDIAN)
+    {
+      *((uint32_t *) &d128.bytes[0])  = (uint32_t) buf[0];
+      *((uint32_t *) &d128.bytes[4])  = (uint32_t) buf[1];
+      *((uint32_t *) &d128.bytes[8])  = (uint32_t) buf[2];
+      *((uint32_t *) &d128.bytes[12]) = (uint32_t) buf[3];
+    }
+  else
+    {
+      *((uint32_t *) &d128.bytes[0])  = (uint32_t) buf[3];
+      *((uint32_t *) &d128.bytes[4])  = (uint32_t) buf[2];
+      *((uint32_t *) &d128.bytes[8])  = (uint32_t) buf[1];
+      *((uint32_t *) &d128.bytes[12]) = (uint32_t) buf[0];
+    }
 
   decimal128ToNumber (&d128, &dn);
   decimal_from_decnumber (r, &dn, &set); 
@@ -530,7 +568,7 @@ decimal_real_to_integer2 (HOST_WIDE_INT *plow, HOST_WIDE_INT *phigh,
   decNumberZero (&dn3);
   decNumberRescale (&dn, &dn2, &dn3, &set);
 
-  /* Conver to REAL_VALUE_TYPE and call appropriate conversion
+  /* Convert to REAL_VALUE_TYPE and call appropriate conversion
      function.  */
   decNumberToString (&dn, string);
   real_from_string (&to, string);