Mail Archives: djgpp-workers/2003/09/03/10:12:53
Eli Zaretskii wrote:
>I feel uneasy with setting bits in the x87 status word (assuming it's
>at all possible, which I'm not certain about). I'd say let the
>hardware do its thing as well as it can, and let's mirror its status
>in a separate variable.
>
The two ways I know to set the x87 status word are either to use the
FLDENV (which loads the complete FPU environment), or to carry out an
arithmetic operation that sets the appropriate bits in the status word.
For instance, loading an SNaN will set the "invalid" bit.
You can copy the status word to memory or the AX register with the FSTSW
instruction, but I don't see what advantages this mirror scheme has over
simply testing and setting the bits of the status register. One
potential pitfall with the direct approach is a math library routine
might do something that sets an exception bit in the course of normal
(unexceptional) computation. I'm trying in vain to think of an example
where this could actually occur. OK, here's one: hypotl(3.E4000L,
4.E4000L). The interesting thing here is that even though the result
doesn't overflow, the obvious implementation by sqrt(x*x + y*y) will
overflow in the computation of x*x + y*y. It might actually be most
efficient to implement it this way, and test for over/underflow. If
over/underflow occurred, one would then go to a more complicated scaled
computation. This approach might be faster than testing each argument,
or using the scaled computation for all arguments. However, doing it
this way would result in the overflow bit being set, because of the
initial failed attempt, even if the result did not overflow.
By the way, I didn't have to worry about this in the hypot routine I
wrote, because the dynamic range of doubles is so much smaller than the
long doubles inside the coprocessor that such an over/underflow can't occur.
If we are thinking about using the exception mechanism, we should
consider how it will affect the "builtin" math functions. For instance,
if you invoke sqrt() in a C program, and don't compile with
-fno-builtin, the compiler will first try to compute the square root by
simply using the fsqrt instruction. If something goes wrong (for
instance, for a negative argument), the library routine is called,
because it presumably has the particular error handling that is
appropriate. We need to make sure that this mechanism still works.
>>In some ways, Annex F makes it easy for the library programmer, since
>>one can often dispense with the argument tests and simply depend on the
>>processor to issue the appropriate exceptions.
>>
>>
>Except that feraiseexception requires us to be able to ``generate''
>such exceptions.
>
>
(see above)
-Eric Rudd
rudd AT cyberoptics DOT com
- Raw text -