diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/dfp.c | 64 |
2 files changed, 59 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cf40b37..63035a0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2008-06-10 Joseph Myers <joseph@codesourcery.com> + + * 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. + 2008-06-10 Vinodha Ramasamy <vinodha@google.com> * value_prob.c (tree_divmod_fixed_value_transform): Use gcov_type. Avoid division by 0. @@ -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); |