public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Craig Howland <howland@LGSInnovations.com>
To: <newlib@sourceware.org>
Subject: Re: [PATCH] Convert 0.0/0.0 to NAN
Date: Thu, 20 Apr 2017 00:25:00 -0000	[thread overview]
Message-ID: <5e08deb1-0528-d5c8-ab92-a9bf8444a48a@LGSInnovations.com> (raw)
In-Reply-To: <CAMY0PLVuZCC_H1EJKwMMzcNr6ZVof7HFGRuaiW8UmVhQhqnnaw@mail.gmail.com>

On 04/19/2017 08:01 PM, Richard Allen wrote:
> Whoops, that was the wrong patch. Attached is correct patch.
>
> On Wed, Apr 19, 2017 at 6:50 PM, Richard Allen <rsaxvc@rsaxvc.net> wrote:
>> With newlib's default compiler flags(-O2 and whatnot),
>> the GCC I'm using creates calls to __aeabi_(f|d)div.
>> This causes a little extra register copying
>> and an unnecessary branch.
>>
>> Additionally, __aeabi_?div may throw exceptions,
>> which is probably not what we want a
>> simple assignment to do.
>>
>> Compiler version tested:
>> arm-none-eabi-gcc (15:5.4.1+svn241155-1) 5.4.1 20160919
>>
>> -Richard
- exc.retval = 0.0/0.0;
+ exc.retval = NAN;

Well, actually, an exception is exactly why it is coded that way; yes, this is 
what this simple assignment is intended to do.  The 0.0/0.0 construct is used so 
that at runtime the floating point flags gets set and yield the NAN result; a 
floating point exception is supposed to be raised.  (The compiler is not allowed 
to optimize it away because of the side effects--which is why you're seeing the 
divide even with -O2.  Although I would guess that in an implementation which 
does not have the side effects, the compiler would be able to substitute the NAN 
at compile time.)
Craig

      reply	other threads:[~2017-04-20  0:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19 23:50 Richard Allen
2017-04-20  0:01 ` Richard Allen
2017-04-20  0:25   ` Craig Howland [this message]

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=5e08deb1-0528-d5c8-ab92-a9bf8444a48a@LGSInnovations.com \
    --to=howland@lgsinnovations.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).