diff options
author | Janis Johnson <janis187@us.ibm.com> | 2007-01-29 23:01:35 +0000 |
---|---|---|
committer | Janis Johnson <janis@gcc.gnu.org> | 2007-01-29 23:01:35 +0000 |
commit | d9a66f98c1cd94c9cba4ba54bf07e39df92614fb (patch) | |
tree | 674d66090dc46dc021568756756f9d8190db5663 /gcc/config | |
parent | 5b18f33782b9b7989dd35f793d68d660575e17e0 (diff) | |
download | gcc-d9a66f98c1cd94c9cba4ba54bf07e39df92614fb.zip gcc-d9a66f98c1cd94c9cba4ba54bf07e39df92614fb.tar.gz gcc-d9a66f98c1cd94c9cba4ba54bf07e39df92614fb.tar.bz2 |
decExcept.c: New.
libdecnumber/
* decExcept.c: New.
* decExcept.h: New.
libgcc/
* Makefile.in (dec-filenames): Add decExcept.
gcc/
* config/dfp-bit.c: Add parameterized support for fp exceptions.
* config/dfp-bit.h: Ditto.
gcc/testsuite/
* gcc.dg/dfp/dfp-except.h: New file.
* gcc.dg/dfp/fe-check.h: New file.
* gcc.dg/dfp/fe-binop.c: New test.
* gcc.dg/dfp/fe-convert-1.c: New test.
* gcc.dg/dfp/fe-convert-2.c: New test.
* gcc.dg/dfp/fe-convert-3.c: New test.
From-SVN: r121317
Diffstat (limited to 'gcc/config')
-rw-r--r-- | gcc/config/dfp-bit.c | 66 | ||||
-rw-r--r-- | gcc/config/dfp-bit.h | 22 |
2 files changed, 88 insertions, 0 deletions
diff --git a/gcc/config/dfp-bit.c b/gcc/config/dfp-bit.c index 47575cc..927804c 100644 --- a/gcc/config/dfp-bit.c +++ b/gcc/config/dfp-bit.c @@ -88,6 +88,19 @@ dfp_unary_op (dfp_unary_func op, DFP_C_TYPE arg) /* Perform the operation. */ op (&res, &arg1, &context); + if (DFP_EXCEPTIONS_ENABLED && context.status != 0) + { + /* decNumber exception flags we care about here. */ + int ieee_flags; + int dec_flags = DEC_IEEE_854_Division_by_zero | DEC_IEEE_854_Inexact + | DEC_IEEE_854_Invalid_operation | DEC_IEEE_854_Overflow + | DEC_IEEE_854_Underflow; + dec_flags &= context.status; + ieee_flags = DFP_IEEE_FLAGS (dec_flags); + if (ieee_flags != 0) + DFP_HANDLE_EXCEPTIONS (ieee_flags); + } + TO_ENCODED (&encoded_result, &res, &context); IEEE_TO_HOST (encoded_result, &result); return result; @@ -115,6 +128,19 @@ dfp_binary_op (dfp_binary_func op, DFP_C_TYPE arg_a, DFP_C_TYPE arg_b) /* Perform the operation. */ op (&res, &arg1, &arg2, &context); + if (DFP_EXCEPTIONS_ENABLED && context.status != 0) + { + /* decNumber exception flags we care about here. */ + int ieee_flags; + int dec_flags = DEC_IEEE_854_Division_by_zero | DEC_IEEE_854_Inexact + | DEC_IEEE_854_Invalid_operation | DEC_IEEE_854_Overflow + | DEC_IEEE_854_Underflow; + dec_flags &= context.status; + ieee_flags = DFP_IEEE_FLAGS (dec_flags); + if (ieee_flags != 0) + DFP_HANDLE_EXCEPTIONS (ieee_flags); + } + TO_ENCODED (&encoded_result, &res, &context); IEEE_TO_HOST (encoded_result, &result); return result; @@ -379,6 +405,17 @@ DFP_TO_DFP (DFP_C_TYPE f_from) TO_INTERNAL (&s_from, &d); TO_ENCODED_TO (&s_to, &d, &context); + if (DFP_EXCEPTIONS_ENABLED && context.status != 0) + { + /* decNumber exception flags we care about here. */ + int ieee_flags; + int dec_flags = DEC_IEEE_854_Inexact | DEC_IEEE_854_Invalid_operation; + dec_flags &= context.status; + ieee_flags = DFP_IEEE_FLAGS (dec_flags); + if (ieee_flags != 0) + DFP_HANDLE_EXCEPTIONS (ieee_flags); + } + IEEE_TO_HOST_TO (s_to, &f_to); return f_to; } @@ -394,6 +431,9 @@ DFP_TO_INT (DFP_C_TYPE x) /* decNumber's decimal* types have the same format as C's _Decimal* types, but they have different calling conventions. */ + /* TODO: Decimal float to integer conversions should raise FE_INVALID + if the result value does not fit into the result type. */ + IEEE_TYPE s; char buf[BUFMAX]; char *pos; @@ -444,6 +484,19 @@ INT_TO_DFP (INT_TYPE i) /* Convert from the floating point string to a decimal* type. */ FROM_STRING (&s, buf, &context); IEEE_TO_HOST (s, &f); + + if (DFP_EXCEPTIONS_ENABLED && context.status != 0) + { + /* decNumber exception flags we care about here. */ + int ieee_flags; + int dec_flags = DEC_IEEE_854_Inexact | DEC_IEEE_854_Invalid_operation + | DEC_IEEE_854_Overflow; + dec_flags &= context.status; + ieee_flags = DFP_IEEE_FLAGS (dec_flags); + if (ieee_flags != 0) + DFP_HANDLE_EXCEPTIONS (ieee_flags); + } + return f; } #endif @@ -492,6 +545,19 @@ BFP_TO_DFP (BFP_TYPE x) /* Convert from the floating point string to a decimal* type. */ FROM_STRING (&s, buf, &context); IEEE_TO_HOST (s, &f); + + if (DFP_EXCEPTIONS_ENABLED && context.status != 0) + { + /* decNumber exception flags we care about here. */ + int ieee_flags; + int dec_flags = DEC_IEEE_854_Inexact | DEC_IEEE_854_Invalid_operation + | DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow; + dec_flags &= context.status; + ieee_flags = DFP_IEEE_FLAGS (dec_flags); + if (ieee_flags != 0) + DFP_HANDLE_EXCEPTIONS (ieee_flags); + } + return f; } #endif diff --git a/gcc/config/dfp-bit.h b/gcc/config/dfp-bit.h index e68f7df..1bbe156 100644 --- a/gcc/config/dfp-bit.h +++ b/gcc/config/dfp-bit.h @@ -32,6 +32,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #include <fenv.h> #include <decRound.h> +#include <decExcept.h> #include "tconfig.h" #include "coretypes.h" #include "tm.h" @@ -120,6 +121,27 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #define DFP_INIT_ROUNDMODE(A) A = DEC_ROUND_HALF_EVEN #endif +#ifdef DFP_EXCEPTIONS_ENABLED +/* Return IEEE exception flags based on decNumber status flags. */ +#define DFP_IEEE_FLAGS(DEC_FLAGS) __extension__ \ +({int _fe_flags = 0; \ + if ((dec_flags & DEC_IEEE_854_Division_by_zero) != 0) \ + _fe_flags |= FE_DIVBYZERO; \ + if ((dec_flags & DEC_IEEE_854_Inexact) != 0) \ + _fe_flags |= FE_INEXACT; \ + if ((dec_flags & DEC_IEEE_854_Invalid_operation) != 0) \ + _fe_flags |= FE_INVALID; \ + if ((dec_flags & DEC_IEEE_854_Overflow) != 0) \ + _fe_flags |= FE_OVERFLOW; \ + if ((dec_flags & DEC_IEEE_854_Underflow) != 0) \ + _fe_flags |= FE_UNDERFLOW; \ + _fe_flags; }) +#else +#define DFP_EXCEPTIONS_ENABLED 0 +#define DFP_IEEE_FLAGS(A) 0 +#define DFP_HANDLE_EXCEPTIONS(A) do {} while (0) +#endif + /* Conversions between different decimal float types use WIDTH_TO to determine additional macros to define. */ |