public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH] Don't call double rint from float powf.
Date: Tue, 12 Dec 2017 12:49:00 -0000	[thread overview]
Message-ID: <20171212124855.GA9113@calimero.vinschen.de> (raw)
In-Reply-To: <1bd39401-e1b2-5be6-4418-9e6a809964da@LGSInnovations.com>

[-- Attachment #1: Type: text/plain, Size: 2559 bytes --]

On Dec 11 19:37, Craig Howland wrote:
> On 12/11/2017 07:08 PM, Jim Wilson wrote:
> > This is the first patch of two to fix problems with the powf code.  I haven't
> > written the other patch yet.
> > 
> > For targets that have only single float support, such as RISC-V rv32imafc, a
> > program using powf ends up pulling in soft-float adddf3 and subdf3 routines.
> > These come from the double rint call, which should be float rintf instead.
> > This makes a significant difference in the size of the resulting program.
> > 
> > I tested this with a simple testcase, with an rint function that calls abort
> > to verify that I'm testing the right code path.  Compiling with
> > "gcc -fno-builtin" I get for the patched and unpatched newlib
> > 
> > gamma02:2195$ ls -lt a.out*
> > -rwxrwxr-x 1 jimw jimw 47012 Dec 11 15:01 a.out
> > -rwxrwxr-x 1 jimw jimw 75680 Dec 11 14:46 a.out.unpatched
> > gamma02:2196$
> > 
> > So the result with the patch is about 60% of the size without the patch.  The
> > test program gives the correct result with the patch.  I also ran the newlib
> > make check, which passed with no regression, but I see it doesn't do much
> > useful.
> > 
> > 	newlib/
> > 	* libm/math/wf_pow.c (powf): Call rintf instead of rint.
> > ---
> >   newlib/libm/math/wf_pow.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c
> > index be453558b..4ca0dc79d 100644
> > --- a/newlib/libm/math/wf_pow.c
> > +++ b/newlib/libm/math/wf_pow.c
> > @@ -127,11 +127,11 @@
> >   		    if (_LIB_VERSION == _SVID_) {
> >   		       exc.retval = HUGE;
> >   		       y *= 0.5;
> > -		       if(x<0.0&&rint(y)!=y) exc.retval = -HUGE;
> > +		       if(x<0.0&&rintf(y)!=y) exc.retval = -HUGE;
> >   		    } else {
> >   		       exc.retval = HUGE_VAL;
> >                          y *= 0.5;
> > -		       if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL;
> > +		       if(x<0.0&&rintf(y)!=y) exc.retval = -HUGE_VAL;
> >   		    }
> >   		    if (_LIB_VERSION == _POSIX_)
> >   		        errno = ERANGE;
> To be most rigorous, "0.0" on the same lines as the rintf() should be "0.0F"
> (as otherwise the comparison strictly should be done in double).  (Not
> addressing the exact change you are making, but is the same class of fix and
> are on the same line of source code.)

Also, HUGE_VAL is double, so it should better be replaced with HUGE_VALF.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2017-12-12 12:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-12  0:14 Jim Wilson
2017-12-12  3:45 ` Craig Howland
2017-12-12 12:49   ` Corinna Vinschen [this message]
2017-12-12 18:14     ` Jim Wilson
2017-12-12 18:05   ` Jim Wilson
2017-12-12 19:00     ` Craig Howland
2017-12-12 19:39 ` [PATCH v2] " Jim Wilson
2017-12-13 10:35   ` Corinna Vinschen

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=20171212124855.GA9113@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --cc=newlib@sourceware.org \
    /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).