fenv.h fixes for softfloat

Ian Lepore freebsd at damnhippie.dyndns.org
Sun Jan 15 01:33:37 UTC 2012


Here are some intermediate results from the llrint() problem before I
call it a night...

The totally degenerate case to get FE_INVALID set is (long long)1.0;

That is, llrint() calls rint() then casts the result to long long.
rint() doesn't even break a sweat converting 1.0 to 1.0 and returns with
no exception flags set, then the cast from 1.0 to 1LL raises FE_INVALID.

With the original value 1.1 instead of 1.0, rint() itself raises
FE_INVALID, in the path that falls out the bottom.  I added printfs:

        printf("rint 7a: except %#x\n", fetestexcept(FE_ALL_EXCEPT));
        INSERT_WORDS(x,i0,i1);
        printf("rint 7b: except %#x\n", fetestexcept(FE_ALL_EXCEPT));
        STRICT_ASSIGN(double,w,TWO52[sx]+x);
        printf("rint 7c: except %#x\n", fetestexcept(FE_ALL_EXCEPT));
        result = w-TWO52[sx];
        printf("rint 8: except %#x i0=%#x i1=%#x x=%g w=%g result=%g\n", fetestexcept(FE_ALL_EXCEPT), i0, i1, x, w, result);
        return result;

And a run using rint(1.1) gave this output:

        rint 7a: except 0
        rint 7b: except 0
        rint 7c: except 0x10
        rint 8: except 0x10 i0=0x3ff20000 i1=0x9999999a x=1.125 w=4.5036e+15 result=1

I think this may be overall bad news.  It seems to imply that certain
normal operations on doubles can raise FE_INVALID as a side effect while
generating valid results, and because of those words in the spec about
how the rounding routines have to behave as if they're a single
operation, I think that means that each rounding routine has to check
for invalid inputs explicitly and raise FE_INVALID, and otherwise don't
let FE_INVALID from rounding or casting leak out to the caller.  Ick.

Or, maybe the fact that (long long)1.0 raises FE_INVALID is the real
problem, like it's not a normal or expected side effect.  Hmmm, for that
matter, what does the spec say about things like casting raising
exceptions?  I think I'll go fix dinner and leave you to ponder that. :)

-- Ian






More information about the freebsd-arm mailing list