This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: x87 register clobber returns "unknown register name" error
- From: Hadrien Grasland <hadrien dot grasland at neel dot cnrs dot fr>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 15 Oct 2015 11:49:41 +0200
- Subject: Re: x87 register clobber returns "unknown register name" error
- Authentication-results: sourceware.org; auth=none
- References: <561F5CC7 dot 6020308 at neel dot cnrs dot fr> <20151015092901 dot GB818 at gate dot crashing dot org>
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) :
"memory");
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) :
"memory");
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.
Hadrien