Unsaved register?

Michael Meissner meissner@cygnus.com
Tue May 29 17:07:00 GMT 2001


On Tue, May 29, 2001 at 04:56:58PM -0700, Erik Walthinsen wrote:
> On Tue, 29 May 2001, Michael Meissner wrote:
> 
> > On Tue, May 29, 2001 at 04:21:45PM -0700, Erik Walthinsen wrote:
> > > I thought that a function call was implicitely supposed to restore all the
> > > state it clobbers?  It's a full C function, no asm at all.  How is the
> > > calling code supposed to know which registers are going to be clobbered?
> >
> > The compiler always implements an ABI that describes which registers are
> > assumed to be clobbered, which are used to pass arguments, which are used to
> > return arguments, and which registers must be preserved across calls.
> > Generally if there is an existing ABI or native compiler, GCC uses that ABI.
> 
> But if the compiler then has all the knowledge of which registers can be
> clobbered across a function call (and presumably %ecx is one of them),
> should it not also automatically avoid allocating that register to a
> variable used in inline asm, esp since it's used both before and after the
> call?
> 
> BTW, I 'fixed' the problem by listing %ecx as a clobbered register in the
> bitstream_get_mmx function, but that's a hack.  I can also 'fix' it by
> turning on the printf at the top of the function, which happens to cause
> gcc to allocate different registers.

However, __asm__ isn't a function call, so rules for what registers are
clobbered or not do not apply.  The whole point of extended asm is to tell the
compiler, exactly what the inputs are, what the outputs are, what else is
clobbered, and whether or not the optimizer can move it.  To quote Henry
Spenser's old signature:

	If you lie to the compiler, it will get its revenge.

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482



More information about the Gcc-bugs mailing list