[PATCH] Convert 0.0/0.0 to NAN
Craig Howland
howland@LGSInnovations.com
Thu Apr 20 00:25:00 GMT 2017
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
More information about the Newlib
mailing list