Mail Archives: djgpp-workers/2000/05/18/11:29:46
I already had a discussion with Eli about some FPU
exceptions problems with specific processors.
I send the source code of a very simple C program that should this bug
The source follows Eli's restriction's that the FPU must be reset
inside the signal handler but when run on a Pentium II 200 MHz (non MMX)
under Win95
I still get a nonzero overridecount
meaning that a second exception is sometimes raised inside
the signal handler itself.
This behavior is documented in the Intel docs, that say the
the FPU status word should be reset before
resetting the IO port.
A possible solution to this problem is to store the fpu state inside
___djgpp_npx_hndlr
and to use this value when clear87 function is called.
All this hassle is due to the fact that Free Pascal compiler should be
able to deal with
FPU exceptions and convert them into software exceptions if the
code is inside a try ... except block !
(Like Delphi does)
>>>>Start of testd.c source
#include <signal.h>
#include <setjmp.h>
#include <float.h>
#define COUNT 100000
jmp_buf t;
int level,count,overridecount,maxlevel;
short fpustate;
void
setfpucontrol ()
{
asm("
movl $0x1332,%eax
pushl %eax
fldcw (%esp)
popl %eax");
}
void
fpesig (i)
int i;
{
level++;
fpustate=_clear87();
longjmp(t,1);
}
void
test ()
{
int i;
for (i=0; i < COUNT; i++)
if (setjmp(t)==0)
{
double j,e;
int k;
k=100;
j=0.0;
e=k/j;
printf("No exception ");
}
else
{
if (level > 1)
overridecount++;
if (level>maxlevel)
maxlevel=level;
setfpucontrol();
count++;
level=0;
}
}
int
maintest ()
{
count=0;
signal(SIGFPE,fpesig);
overridecount=0;
maxlevel=0;
setfpucontrol();
test();
printf("Number of signal %d, overridecount %d\r\n",count,overridecount);
if (count != COUNT || overridecount != 0)
{
printf("Problems !!! maxlevel = %d",maxlevel);
return 1;
}
return 0;
}
int
main ()
{
return maintest();
}
>>> End of source
Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller AT ics DOT u-strasbg DOT fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99
- Raw text -