aboutsummaryrefslogtreecommitdiff
path: root/gcc/dfp.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2008-06-10 23:43:09 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2008-06-10 23:43:09 +0000
commit4d6f3aadf5cae5784452dc4e71596d8bfb9722dd (patch)
treeaaae18cb379d8aaa4351816af260f701d6721cc1 /gcc/dfp.c
parent5b17b7ae7a1654f4555cce7f1339d4dad60e7f56 (diff)
gcc:
* dfp.c (WORDS_BIGENDIAN): Define to 0 if not defined. (encode_decimal64, decode_decimal64, encode_decimal128, decode_decimal128): Reverse order of 32-bit parts of value if host and target endianness differ. libdecnumber: * dconfig.h: New. * decContext.c, decExcept.c, decExcept.h, decLibrary.c, decNumber.c, decNumberLocal.h, decRound.c, dpd/decimal128.c, dpd/decimal32.c, dpd/decimal64.c: Include dconfig.h not config.h. * dpd/decimal128Local.h (decimal128SetSign, decimal128ClearSign, decimal128FlipSign): Use WORDS_BIGENDIAN not FLOAT_WORDS_BIG_ENDIAN. * bid/host-ieee128.c: Include dconfig.h. (__host_to_ieee_128, __ieee_to_host_128): Swap 64-bit halves of value if WORDS_BIGENDIAN. libgcc: * Makefile.in (DECNUMINC): Remove -I$(MULTIBUILDTOP)../../libdecnumber. * gstdint.h: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@136641 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/dfp.c')
-rw-r--r--gcc/dfp.c64
1 files changed, 52 insertions, 12 deletions
diff --git a/gcc/dfp.c b/gcc/dfp.c
index fde3b84bda5..43262380af5 100644
--- a/gcc/dfp.c
+++ b/gcc/dfp.c
@@ -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. */
@@ -173,8 +177,16 @@ 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. */
@@ -190,8 +202,16 @@ 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);
@@ -213,10 +233,20 @@ 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. */
@@ -232,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);