diff options
author | Joseph Myers <joseph@codesourcery.com> | 2008-06-11 00:43:09 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2008-06-11 00:43:09 +0100 |
commit | bc6d4c3f08404ffb1cb9379649d60bace4d15258 (patch) | |
tree | aaae18cb379d8aaa4351816af260f701d6721cc1 /gcc/dfp.c | |
parent | 0178d64465a03fdfa6e37f6f0750ad7d55e446f1 (diff) | |
download | gcc-bc6d4c3f08404ffb1cb9379649d60bace4d15258.zip gcc-bc6d4c3f08404ffb1cb9379649d60bace4d15258.tar.gz gcc-bc6d4c3f08404ffb1cb9379649d60bace4d15258.tar.bz2 |
dfp.c (WORDS_BIGENDIAN): Define to 0 if not defined.
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.
From-SVN: r136641
Diffstat (limited to 'gcc/dfp.c')
-rw-r--r-- | gcc/dfp.c | 64 |
1 files changed, 52 insertions, 12 deletions
@@ -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); |