I would think you only need to configure the FPU the way that you require it, not save and restore the previous state.
As I said, I would expect each application to set up the FPU as it requires. It really cannot assume that the FPU is in some
"default" state, AFAIK.
(However, it is true that the FPU is in some well-known state at power-on.)
In any case, I would think you only need to program this once, then call the procedure from each entry point -- at worst.
Alternatively, perhaps you can put the code into a single procedure that is called when the DLL is loaded. I am not familiar with
Windows DLLs. But it is common practice in other architectures.
The FPU is is the state 0x4000 every time my DLL
is called from Excel. I believe that 0x4000
means round up on the SSE2.
I am using the following code to reset the FPU in
my DLL:
unsigned checkMathCoprocessorStatus ()
{
unsigned old87Status = 0;
unsigned new87ControlWord = 0;
unsigned new87ControlMask = 0;
unsigned new87result = 0;
old87Status = _status87 ();
if (old87Status != 0)
{
char msg [4096];
sprintf (msg, "\nThe Math Coprocessor status is 0x%x, resetting to zero\n\n", old87Status);
writeLineToScreen (msg);
new87result = _control87 (new87ControlWord, new87ControlMask);
}
return old87Status;
}
Lynn