This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: gcc using clobbered register as input with inline assembly
- To: Zack Weinberg <zackw at stanford dot edu>
- Subject: Re: gcc using clobbered register as input with inline assembly
- From: Bernd Schmidt <bernds at redhat dot com>
- Date: Tue, 27 Mar 2001 13:07:42 +0100 (BST)
- Cc: Timur Tabi <ttabi at interactivesi dot com>, <gcc-bugs at gcc dot gnu dot org>
On Mon, 26 Mar 2001, Zack Weinberg wrote:
> On Mon, Mar 26, 2001 at 01:08:32PM -0600, Timur Tabi wrote:
> > ** Reply to message from "Zack Weinberg" <zackw@stanford.edu> on Mon, 26 Mar
> > 2001 10:20:21 -0800
> >
> >
> > > > According to the documentation, because I specified eax and edx as
> > > > clobbered registers, gcc should not be using them as inputs or outputs.
> > > > But that's exactly what's happening in my case.
> > >
> > > Clobbers happen *after* the asm completes. You have to do the moves
> > > separately, or let the compiler do them for you, e.g:
> >
> > I don't understand this. What good is it to specify clobbers if they happen
> > after the assembly? I have no control over what happens outside the assembly
> > code! I thought the point behind clobbers was to inform the compiler of
> > specific registers that my assembly code modifies.
>
> Mm, let me rephrase. You wrote
>
> > __asm__ __volatile__ (
> > "rdtsc \n\t"
> > "mov %%eax, (%1) \n\t"
> > "mov %%edx, 4(%1) \n\t"
> > : "=m" (*pTime)
> > : "r" (pTime)
> > : "eax", "edx");
>
> As far as GCC is concerned, that is *one* machine instruction which:
> - takes one input, the value of pTime, in a register
> - places a value into memory at *pTime
> - destroys the values in eax and edx
> in that order. It has no way of knowing that there's three machine
> instructions embedded in that text string, and that the destruction of
> eax and edx happens before the input is used.
That's not correct. Clobbered registers are unavailable for inputs.
All gcc versions before 2.95 (and that includes egcs-1.1 which Timur was
using) failed to get this right on x86, however.
Bernd