[PATCH] Builtin function roundeven folding implementation

Tejas Joshi tejasjoshi9673@gmail.com
Wed Aug 14 07:24:00 GMT 2019


Hi.
Here is a clean patch that does not fold roundeven resulting for
integer type and the conditions for folding functions
round/ceil/floor/roundeven and trunc only checks for signaling NaN.
This patch also conforms to GNU's coding style and standards. The fact
that it should be CASE_MATHFN_FLOATN rather than CASE_MATHFN for
roundeven is corrected in i386 expansion patch.

Thanks,
Tejas

gcc/ChangeLog:

2019-06-12  Tejas Joshi  <tejasjoshi9673@gmail.com>

    * builtins.c (mathfn_built_in_2): Added CASE_MATHFN 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.
    * 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.

gcc/testsuite/ChangeLog:

2019-06-12  Tejas Joshi  <tejasjoshi9673@gmail.com>

    * gcc.dg/torture/builtin-round-roundeven.c: New test.
    * gcc.dg/torture/builtin-round-roundevenf128.c: New test.

On Sat, 10 Aug 2019 at 02:15, Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Fri, 28 Jun 2019, Tejas Joshi wrote:
>
> > +    CASE_CFN_ROUNDEVEN:
> > +    CASE_CFN_ROUNDEVEN_FN:
> > +      if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math)
>
> Checking flag_errno_math here does not make sense.  roundeven never sets
> errno (at least, TS 18661-1 makes it implementation-defined whether sNaN
> input counts as a domain error, but I'm not aware of implementations that
> make it a domain error and set errno, and typically GCC follows glibc in
> such cases in the absence of known implementations requiring a different
> approach).
>
> The only case where you need to avoid folding is where the argument is a
> signaling NaN (it's fine to fold for quiet NaNs).  In that case, you need
> to avoid folding to avoid losing an exception (if the user cares about
> signaling NaNs, they probably care about exceptions) - so it still doesn't
> matter whether the library implementation also sets errno or not.
>
> (Yes, this means the existing ceil / floor / round checks should be
> adjusted just to check for signaling NaN, though that's fairly cosmetic as
> calls to those functions with quiet NaN argument still get folded via
> match.pd.  trunc ought also check for signaling NaN rather than folding
> unconditionally, so all those functions should end up with the same
> conditions for folding.)
>
> > @@ -898,6 +907,10 @@ fold_const_call_ss (wide_int *result, combined_fn fn,
> >        return fold_const_conversion (result, real_round, arg,
> >                                   precision, format);
> >
> > +    CASE_CFN_ROUNDEVEN:
> > +    CASE_CFN_ROUNDEVEN_FN:
> > +      return fold_const_conversion (result, real_roundeven, arg, precision, format);
> > +
>
> This is the version of fold_const_call_ss for functions returning a result
> of integer type; roundeven returns an integer value in a floating-point
> type.  I don't think this code should be there, and I don't think this
> version of the function should be called at all for roundeven.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: roundeven.diff
Type: text/x-patch
Size: 9685 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190814/f7b65fa8/attachment.bin>


More information about the Gcc-patches mailing list