[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] trying to fix the bug of unclean FPU st(0)
From: |
Soloist Deng |
Subject: |
Re: [Tinycc-devel] trying to fix the bug of unclean FPU st(0) |
Date: |
Tue, 9 Jun 2009 12:33:52 +0800 |
Hi,
> I didn't look your change closely yet, but I confirmed that your
> change doesn't break tcctest on both x86 and x86-64. I think we may
> want to see a small code to reproduce the bug you found so that we can
> add the code into tcctest to avoid future regressions. Could you show
> the code the original tcc outputs wrong code?
//////////////////////////////////////
void
foo()
{
double v = 1.23456;
}
int
main()
{
// unmask FPU #IE(Invalid Operation Exception) flag of control word
unsigned short custom = 0;
asm("fstcw %0"
:
: "m" (custom));
custom &= 0xfffe;
asm("fldcw %0"
:
: "m" (custom));
// before foo(), FPU registers stack is empty
foo();
// after foo(), st(0) is left unclean
asm("fld1;"
"fld1;"
"fld1;"
"fld1;"
"fld1;"
"fld1;"
"fld1;"
"fld1;");
// fnop will throw a FPU #IE exception
asm("fnop");
return 0;
}
///////////////////////////////////////////////////////
This program will signal SIGFPE. If comment `foo()', it works
well. Because `foo()' left st(0) unclean, the following eight
successive
`fld1' will cause registers stack overflow.
The optimized code generated by gcc or msvc always assume that all
eight FPU floating registers are freely available when entering a
function,
so it will make full use of all eight registers like code above. That
cause the problem.
There was a
post(http://lists.gnu.org/archive/html/tinycc-devel/2008-01/msg00002.html)
talking about this problem.