i386 floating point asm in mathinline.h (gcc related)

Andreas Jaeger aj@suse.de
Tue Oct 19 07:30:00 GMT 1999


Hi,

I need a wee bit of help with understanding floating point asm in
mathinline.h.  It might be that glibc has wrong asms - but I don't
know enough to give a definite answer.

Currently we use e.g.
 __inline_mathop (log, "fldln2; fxch; fyl2x")
which expands to (I simplified a little bit):

inline double log (double __x)
{
  register double __result;
  __asm __volatile__ ("fldln2; fxch; fyl2x" : "=t" (__result) : "0" (__x))
  return __result;
}

We push two elements on the fp stack without telling gcc about it.
What happens if we get a stack overflow?  Does the above asm really
handle this problem?

An alternative solution is to use two asm statements and specify
explicitly how we change the stack:

inline double log (double __x)
{
  register double __result;
  register long double __value;
  
  __asm ("fldln2": "=t" (__value));
  __asm ("fyl2x" : "=t" (__value) : "0" (__x), "u" (__value) : "st(1)" );
  return __result;
}

I do think [1] that the above is correct - but is it as efficient as
possible?

This has been brought to my attention by Tim Prince
<tprince@computer.org>.  The code is from a patch he send me which I'm
currently looking at.

Andreas

Footnotes: 
[1]  My knowledge of i386 asm in gcc is not good - please double check
     everything I say before you believe me ;-)

-- 
 Andreas Jaeger   
  SuSE Labs aj@suse.de	
   private aj@arthur.rhein-neckar.de


More information about the Libc-alpha mailing list