Documentation of x87 extended inline assembly

Dieter Buerssner buers@gmx.de
Tue May 16 02:17:00 GMT 2000


There seems to be some lack of documentation of x87 inline assembly 
for gcc. One problem is, that I have found no way, to tell gcc, how 
many additional entries in the FPU-stack the inline assembly will 
use. A small example may be

long double my_logl(long double x)
{
  long double y;
  __asm__ volatile(
    "fldln2\n"
    "fldl   %1\n"
    "fyl2x"
    : "=t" (y) : "m" (x));
  return y;
}

For a inline version, this could be formulated as

__inline__ long double my_logl(long double x)
{
  long double y;
  __asm__ volatile(
    "fldln2\n"
    "fxch   %%st(1)\n"
    "fyl2x"
    : "=t" (y) : "0" (x));
  return y;
}

The non inlined version will probably be ok. When inlined, there 
seems to be the possibility, that gcc will already have cached 7 
values on the FPU-stack, and the stack will overflow.

Similar, one might want to write

long doube logbasel(long double x)
{
  static const long double log2const=...;
  long double y;
  __asm__ volatile("fyl2x", "=t" (y): "u" (log2const), "0" (x)
                            : /* what goes here? "u"? */);
  return y;
}

I have not found documentation, what there should be in the clobber
list here.

Do I need, to write this as

  long double y, unused;
  __asm__ volatile("fyl2x;fld %%st": "=t" (y), "=u" (unused)
     : "1" (log2const), "0" (x));

A similar problem is i.e. with fxtract, that produces one additional 
entry in the FPU-stack. The following seems to work

  long double x, y, z;
  __asm__ volatile("fxtract" : "=t" (y), "=u" (z) : "0" (x));

I have not found this feature documented, but it seeems logical.

Regards,
Dieter Buerssner



More information about the Gcc-bugs mailing list