diff options
author | Tejas Joshi <tejasjoshi9673@gmail.com> | 2019-08-26 12:32:29 +0000 |
---|---|---|
committer | Martin Jambor <jamborm@gcc.gnu.org> | 2019-08-26 14:32:29 +0200 |
commit | 7d7b99f95bf2517caab5f9300090b471135b4fc0 (patch) | |
tree | c215f66b35c9f3508ceb670fbaeae05b7d223c3d /gcc/fold-const-call.c | |
parent | 48a31a09839b12127ce7c40d7adc4bd5bf1d3407 (diff) | |
download | gcc-7d7b99f95bf2517caab5f9300090b471135b4fc0.zip gcc-7d7b99f95bf2517caab5f9300090b471135b4fc0.tar.gz gcc-7d7b99f95bf2517caab5f9300090b471135b4fc0.tar.bz2 |
Builtin function roundeven folding implementation
2019-08-26 Tejas Joshi <tejasjoshi9673@gmail.com>
* builtins.c (mathfn_built_in_2): Added CASE_MATHFN_FLOATN
for ROUNDEVEN.
* builtins.def: Added function definitions for roundeven function
variants.
* fold-const-call.c (fold_const_call_ss): Added case for roundeven
function call. Adjust condition for floor, ceil, trunc and round.
* fold-const.c (negate_mathfn_p): Added case for roundeven function.
(tree_call_nonnegative_warnv_p): Added case for roundeven function.
(integer_valued_real_call_p): Added case for roundeven function.
* real.c (is_even): New function. Returns true if real number is even,
otherwise returns false.
(is_halfway_below): New function. Returns true if real number is
halfway between two integers, else return false.
(real_roundeven): New function. Round real number to nearest integer,
rounding halfway cases towards even.
* real.h (real_value): Added descriptive comments. Added function
declaration for roundeven function.
* doc/extend.texi (Other Builtins): List roundeven variants among
functions which can be handled as builtins.
gcc/testsuite/ChangeLog:
2019-08-26 Tejas Joshi <tejasjoshi9673@gmail.com>
* gcc.dg/torture/builtin-round-roundeven.c: New test.
* gcc.dg/torture/builtin-round-roundevenf128.c: New test.
From-SVN: r274927
Diffstat (limited to 'gcc/fold-const-call.c')
-rw-r--r-- | gcc/fold-const-call.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index e21d8e11..3a14d2a 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -836,7 +836,7 @@ fold_const_call_ss (real_value *result, combined_fn fn, CASE_CFN_FLOOR: CASE_CFN_FLOOR_FN: - if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math) + if (!REAL_VALUE_ISSIGNALING_NAN (*arg)) { real_floor (result, format, arg); return true; @@ -845,7 +845,7 @@ fold_const_call_ss (real_value *result, combined_fn fn, CASE_CFN_CEIL: CASE_CFN_CEIL_FN: - if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math) + if (!REAL_VALUE_ISSIGNALING_NAN (*arg)) { real_ceil (result, format, arg); return true; @@ -854,18 +854,31 @@ fold_const_call_ss (real_value *result, combined_fn fn, CASE_CFN_TRUNC: CASE_CFN_TRUNC_FN: - real_trunc (result, format, arg); - return true; + if (!REAL_VALUE_ISSIGNALING_NAN (*arg)) + { + real_trunc (result, format, arg); + return true; + } + return false; CASE_CFN_ROUND: CASE_CFN_ROUND_FN: - if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math) + if (!REAL_VALUE_ISSIGNALING_NAN (*arg)) { real_round (result, format, arg); return true; } return false; + CASE_CFN_ROUNDEVEN: + CASE_CFN_ROUNDEVEN_FN: + if (!REAL_VALUE_ISSIGNALING_NAN (*arg)) + { + real_roundeven (result, format, arg); + return true; + } + return false; + CASE_CFN_LOGB: return fold_const_logb (result, arg, format); |