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: Thu, 22 Aug 2019 16:56:00 -0000 [thread overview]
Message-ID: <CACMrGjDFMFPRckKC-rx7-LRPXBou-O_xV=_kEuMVL4BSMSKkew@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1908221633440.29112@digraph.polyomino.org.uk>
> I think you should have at least four tests of sign of zero result
> (arguments -0.5, -0.0, 0.0 and 0.5). Probably also tests of values
> between +/- 0.5 and 0, e.g. test -0.25 and 0.25 as well.
Okay, I have made the following changes and again, the tests pass for roundeven.
void
real_roundeven (REAL_VALUE_TYPE *r, format_helper fmt,
const REAL_VALUE_TYPE *x)
{
if (is_halfway_below (x))
{
/* Special case as -0.5 rounds to -0.0 and
similarly +0.5 rounds to +0.0. */
if (REAL_EXP (x) == 0)
{
*r = *x;
clear_significand_below (r, SIGNIFICAND_BITS);
}
else
{
do_add (r, x, &dconsthalf, x->sign);
if (!is_even (r))
do_add (r, r, &dconstm1, x->sign);
}
if (fmt)
real_convert (r, fmt, r);
}
else
real_round (r, fmt, x);
}
Tests :
/* { dg-do link } */
extern int link_error (int);
#define TEST(FN, VALUE, RESULT) \
if (__builtin_##FN (VALUE) != RESULT) link_error (__LINE__);
int
main (void)
{
TEST(roundeven, 0, 0);
TEST(roundeven, 0.5, 0);
TEST(roundeven, -0.5, 0);
TEST(roundeven, 6, 6);
TEST(roundeven, -8, -8);
TEST(roundeven, 2.5, 2);
TEST(roundeven, 3.5, 4);
TEST(roundeven, -1.5, -2);
TEST(roundeven, 3.499, 3);
TEST(roundeven, 3.501, 4);
if (__builtin_copysign (1, __builtin_roundeven (-0.5)) != -1)
link_error (__LINE__);
if (__builtin_copysign (1, __builtin_roundeven (-0.0)) != -1)
link_error (__LINE__);
if (__builtin_copysign (-1, __builtin_roundeven (0.5)) != 1)
link_error (__LINE__);
if (__builtin_copysign (-1, __builtin_roundeven (0.0)) != 1)
link_error (__LINE__);
if (__builtin_copysign (1, __builtin_roundeven (-0.25)) != -1)
link_error (__LINE__);
if (__builtin_copysign (-1, __builtin_roundeven (0.25)) != 1)
link_error (__LINE__);
return 0;
}
Thanks,
Tejas
On Thu, 22 Aug 2019 at 22:05, Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Thu, 22 Aug 2019, Tejas Joshi wrote:
>
> > > I'm concerned that this would produce +0.0 for an argument of -0.5 (via
> > > -0.5 - 0.5 - -1.0 producing +0.0) when it needs to produce -0.0.
> >
> > Would the following overhaul be acceptable as the condition is
> > specialized for -0.5 and +0.5 only. This seems to solve the problem. I
> > did test the roundeven tests and it passes the tests.
>
> I think that would be reasonable with a comment added to explain that it's
> ensuring the correct sign of a zero result.
>
> > if (__builtin_copysign (1, __builtin_roundeven (-0.5)) != -1)
> > link_error (__LINE__);
>
> I think you should have at least four tests of sign of zero result
> (arguments -0.5, -0.0, 0.0 and 0.5). Probably also tests of values
> between +/- 0.5 and 0, e.g. test -0.25 and 0.25 as well.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
next prev parent reply other threads:[~2019-08-22 16:56 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 [this message]
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
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='CACMrGjDFMFPRckKC-rx7-LRPXBou-O_xV=_kEuMVL4BSMSKkew@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).