On Fri, 23 Aug 2019, Tejas Joshi wrote:

> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 9a766e4ad63..5149d901a96 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -2056,6 +2056,7 @@ mathfn_built_in_2 (tree type, combined_fn fn)
>      CASE_MATHFN (REMQUO)
>      CASE_MATHFN_FLOATN (RINT)
>      CASE_MATHFN_FLOATN (ROUND)
> +    CASE_MATHFN (ROUNDEVEN)

This should use CASE_MATHFN_FLOATN, as for the other round-to-integer 
functions.

> +  /* Check lowest bit, if not set, return true.  */
> +  else if (REAL_EXP (r) <= SIGNIFICAND_BITS)
> +  {
> +    unsigned int n = SIGNIFICAND_BITS - REAL_EXP (r);
> +    int w = n / HOST_BITS_PER_LONG;
> +
> +    unsigned long num = ((unsigned long)1 << (n % HOST_BITS_PER_LONG));
> +
> +    if ((r->sig[w] & num) == 0)
> +      return true;

Fix the indentation here (the braces should be indented two columns from 
the "else", the contents then two columns from the braces).

> +  }
> +
> +  else

And remove the stray blank line before "else".

> +/* Return true if R is halfway between two integers, else return
> +   false.  The function is not valid for rvc_inf and rvc_nan classes.  */
> +
> +bool
> +is_halfway_below (const REAL_VALUE_TYPE *r)
> +{
> +  gcc_assert (r->cl != rvc_inf);
> +  gcc_assert (r->cl != rvc_nan);
> +  int i;

Explicitly check for rvc_zero and return false in that case (that seems to 
be the convention in real.c, rather than relying on code using REAL_EXP to 
do something sensible for zero, which has REAL_EXP of 0).

> +  else if (REAL_EXP (r) < SIGNIFICAND_BITS)
> +  {

Another place to fix indentation.

> +void
> +real_roundeven (REAL_VALUE_TYPE *r, format_helper fmt,
> +             const REAL_VALUE_TYPE *x)
> +{
> +  if (is_halfway_below (x))
> +  {

Again, fix indentation throughout this function.

The patch is OK with those fixes, assuming the fixed patch passes testing.  
I encourage a followup looking for and fixing further places in the source 
tree that handle round-to-integer function families (ceil / floor / trunc 
/ round / rint / nearbyint) and should handle roundeven as well, as that 
would lead to more optimization of roundeven calls.  Such places aren't 
that easy to search for because most of those names are common words used 
in other contexts in the compiler.  But, for example, match.pd has 
patterns

/* trunc(trunc(x)) -> trunc(x), etc.  */

/* f(x) -> x if x is integer valued and f does nothing for such values.  */

 /* truncl(extend(x)) -> extend(trunc(x)), etc., if x is a double.  */

 /* truncl(extend(x)) and trunc(extend(x)) -> extend(truncf(x)), etc.,
    if x is a float.  */

which should apply to roundeven as well.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to