x87 register clobber returns "unknown register name" error

Hadrien Grasland hadrien.grasland@neel.cnrs.fr
Thu Oct 15 09:49:00 GMT 2015

Le 15/10/2015 11:29, Segher Boessenkool a écrit :
> I'm not sure you can clobber stack regs at all.  You could add it as
> an output and just not use the result?  Like
> asm ("fyl2xp1" : "=t" (result), "=u" (dummy) : "0" (x), "1" (y));
> Segher

Indeed, this compiles and works as intended :

    float st0; // Will not be used, just a way to clobber the
floating-point stack
    asm volatile ("fstps (%2)" :
                  "=t" (st0) :
                  "0" (input), "r" (output) :

And for the code aesthetes out there, I can also think of a version that
looks better and uses less storage, at the cost of erasing input :

    asm volatile ("fstps (%2)" :
                  "+t" (input) :
                  "r" (output) :

One thing that makes me sad is that GCC might perform a useless x87
stack pop (depending on how clever its optimizer is), which can become
an issue in a performance-sensitive code path.

Another is that the documentation suggests that it is possible to
clobber stack registers (at the very bottom of
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands ),
whereas it seems impossible in practice. So I guess that either the
ability to clobber stack registers should be added to GCC, or the
documentation should be fixed to reflect this situation.


More information about the Gcc-help mailing list