From: Tejas Joshi <tejasjoshi9673@gmail.com>
To: gcc@gcc.gnu.org
Cc: Martin Jambor <mjambor@suse.cz>, hubicka@ucw.cz, joseph@codesourcery.com
Subject: Re: [PATCH] Builtin function roundeven folding implementation
Date: Sun, 25 Aug 2019 08:25:00 -0000 [thread overview]
Message-ID: <CACMrGjA-vfj1ahKAKr3X22B=dc_W--fK6uSFLLRuj2wM4kM3Gg@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1908232023080.19272@digraph.polyomino.org.uk>
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 <joseph@codesourcery.com> 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
next prev parent reply other threads:[~2019-08-25 8:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CACMrGjCu54zN+Smc7+3JF8MBZV76HXwaP-vk1HFTQGhRc=Toww@mail.gmail.com>
[not found] ` <alpine.DEB.2.21.1908092021090.31221@digraph.polyomino.org.uk>
[not found] ` <CACMrGjCPNr+Hjz--CL6ocV5y3GqGp13fpQCXtXJT4qeGQWk86A@mail.gmail.com>
[not found] ` <ri636hug2zr.fsf@suse.cz>
[not found] ` <alpine.DEB.2.21.1908211156360.6172@digraph.polyomino.org.uk>
[not found] ` <ri6pnkye7ll.fsf@suse.cz>
[not found] ` <alpine.DEB.2.21.1908211906340.25161@digraph.polyomino.org.uk>
[not found] ` <ri6ftlte12y.fsf@suse.cz>
[not found] ` <alpine.DEB.2.21.1908221426570.27000@digraph.polyomino.org.uk>
2019-08-22 16:28 ` Tejas Joshi
2019-08-22 16:35 ` Joseph Myers
2019-08-22 16:56 ` Tejas Joshi
2019-08-22 17:00 ` Joseph Myers
[not found] ` <CACMrGjA3UyUYcShruM-tiT=rqBiSLX9cmSVmpX0G6SfOq_r4EQ@mail.gmail.com>
[not found] ` <alpine.DEB.2.21.1908232023080.19272@digraph.polyomino.org.uk>
2019-08-25 8:25 ` Tejas Joshi [this message]
2019-08-25 9:38 ` Martin Jambor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACMrGjA-vfj1ahKAKr3X22B=dc_W--fK6uSFLLRuj2wM4kM3Gg@mail.gmail.com' \
--to=tejasjoshi9673@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=joseph@codesourcery.com \
--cc=mjambor@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).