This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
extended inline asm question on FPU stack
- To: egcs at egcs dot cygnus dot com
- Subject: extended inline asm question on FPU stack
- From: Martin Kahlert <martin dot kahlert at mchp dot siemens dot de>
- Date: Mon, 15 Feb 1999 15:55:48 +0100
- Reply-To: martin dot kahlert at mchp dot siemens dot de
Hi,
I have a problem with extended inline asm:
This program doesn't work as (i) expected:
/* Try to return 1+buffer */
float f(float buffer)
{
asm volatile (
"fld1\n\t"
"fadd %0\n\t"
"fstps (%1)"
:
: "f" (buffer),"r" (&buffer)
: "memory");
return buffer;
}
int main(int argc,const char *argv[])
{
printf("%f\n",f(1.1));
return 0;
}
It prints 2.0 instead of 2.1.
because it doubles 1 and doesn't add buffer to 1.
How could this be corrected?
One solution would be
asm volatile (
"fld1\n\t"
"fadd (%0)\n\t"
"fstps (%1)"
:
: "r" (&buffer),"r" (&buffer)
: "memory");
but that isn't as nice and the above one would be much more
intuitive for me.
I didn't find anything in the info pages about fpu-stack on x86.
Thanks, in advance,
Martin.
--
Your mouse has moved. Windows must be restarted for the change
to take effect. Reboot now?