From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23071 invoked by alias); 25 Aug 2019 08:25:58 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 23061 invoked by uid 89); 25 Aug 2019 08:25:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Received:Sun, HX-Received:a50 X-HELO: mail-ed1-f68.google.com Received: from mail-ed1-f68.google.com (HELO mail-ed1-f68.google.com) (209.85.208.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 25 Aug 2019 08:25:56 +0000 Received: by mail-ed1-f68.google.com with SMTP id h13so21414272edq.10 for ; Sun, 25 Aug 2019 01:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NW0K3LSYE4L3dX8XhLwy/CdgC79wm4o/FktFiUbdGY4=; b=Vf342A7Mbu7utjguei6cEE6ev1NAZCbSXglInp7mWmMuWWXtzxjZLjzobdqsptCBlh fSDKy/Ac2X9QZlzG1Sq6G8q9zi3j/HRBfBAtprpO7N7Fc927QnzdDokKLAfhK83fftGV 6vhFuvvYn7ls+Qg+1INgBEMkNaVXInHxElILxQZe3OvbFi5IVBf1fmKU5avjD4BVP0bq Q5keAZ51FGvOjJPSGvhd2tooXpFKJOBPfJmzdDVR10IQx4qA9Ka7/ncfgRB5W4aWhCti 9lzb8uptTkbds6/ckErjuSpmsFCySOTa5sI1ITbTRdRwpNaQTaDqGTMsXw2+l+7xdm0z ktig== MIME-Version: 1.0 References: In-Reply-To: From: Tejas Joshi Date: Sun, 25 Aug 2019 08:25:00 -0000 Message-ID: Subject: Re: [PATCH] Builtin function roundeven folding implementation To: gcc@gcc.gnu.org Cc: Martin Jambor , hubicka@ucw.cz, joseph@codesourcery.com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00209.txt.bz2 I have made the respective changes and fixed the indentations and it passes the 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 I will follow up to make these optimizations for sure. Thanks, Tejas On Sat, 24 Aug 2019 at 02:08, Joseph Myers wrote: > > 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