aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/dfp-bit.c
diff options
context:
space:
mode:
authorJanis Johnson <janis187@us.ibm.com>2007-01-29 23:01:35 +0000
committerJanis Johnson <janis@gcc.gnu.org>2007-01-29 23:01:35 +0000
commitd9a66f98c1cd94c9cba4ba54bf07e39df92614fb (patch)
tree674d66090dc46dc021568756756f9d8190db5663 /gcc/config/dfp-bit.c
parent5b18f33782b9b7989dd35f793d68d660575e17e0 (diff)
downloadgcc-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/dfp-bit.c')
-rw-r--r--gcc/config/dfp-bit.c66
1 files changed, 66 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