From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3888 invoked by alias); 23 Aug 2019 20:38:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 3875 invoked by uid 89); 23 Aug 2019 20:38:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: esa3.mentor.iphmx.com Received: from esa3.mentor.iphmx.com (HELO esa3.mentor.iphmx.com) (68.232.137.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 23 Aug 2019 20:38:50 +0000 IronPort-SDR: +RZo6xxv1+YLwbQS91RSWS2Q1v+LmmkMA34BYEliMP84Tmv3do5JzTiXRBB+jiF5hV4y81oWbL 7jbM44hxLL9OkrZVG+/+yEN5tp3upiBZrIvw15kQWzv2jKBzbrj+vpYfl1aOYR8KFXMAvB8Zx3 PRa/CSbd1Rs+6vz5/sQoHV/GdYhjrIgcgtFG9c20rF7N6Yt7S42Ruyt9VtYAVciDTaIP7Tp/l+ ZkGF8pF10Nl4xyW4aTX0S7j+oxzigZxVUiOBMClTbuozSUE+Crys1G/SVnzkUWdF3aLzrZi7eT 158= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 23 Aug 2019 12:38:48 -0800 IronPort-SDR: yqXJQkNip1QiTXA8BHll/haTvgWEFGGoAJys14NbW3M0k2ncWdZwSnYs7wStBtfUPw4I1QqA5W 2m/JYms9Kvu77wQCtItlpg308UW8f8Rgi/yvQne663a4YH4dDkloRfUgDFAwXa6TayfyjlzNoc x3K/MxgVh8bw39gPpfYUHwZ3dKqczoK2PzXDGBl7sbqx/S6PhRzBebySxd0ecXeefsE/vsrKDn rSZn38Htg3gt1M0wepah4x8iRWIcuK+K3V4KXykbrN2E+sbb7uWyjYdAHnwEy7uzYfy4xR49BD VV4= Date: Fri, 23 Aug 2019 21:24:00 -0000 From: Joseph Myers To: Tejas Joshi CC: , Martin Jambor , Subject: Re: [PATCH] Builtin function roundeven folding implementation In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Return-Path: joseph@codesourcery.com X-SW-Source: 2019-08/txt/msg01682.txt.bz2 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 joseph@codesourcery.com