public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* clobber list in inline assembly for calls
@ 2011-01-08  0:31 Daniel Mierswa
  2011-01-08  4:50 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mierswa @ 2011-01-08  0:31 UTC (permalink / raw)
  To: gcc-help

Good day,

I was wondering which registers I have to clobber or which special
strings I have to put into the clobber list if all I'm going to do is:

asm("call %0;" ::"m"(addr_of_myfunc));

As I can't tell what the function is doing I may have to clobber all
registers or am I wrong?
I had in mind to clobber "cc" plus "eax", "ecx", "edx" which are by the
i386 ABI not preserved for the caller.

I couldn't find any relevant documentation about this in several
How-Tos. Thanks in advance for any reponses.

-- 
Mierswa, Daniel

If you still don't like it, that's ok: that's why I'm boss. I simply
know better than you do.
               --- Linus Torvalds, comp.os.linux.advocacy, 1996/07/22

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: clobber list in inline assembly for calls
  2011-01-08  0:31 clobber list in inline assembly for calls Daniel Mierswa
@ 2011-01-08  4:50 ` Ian Lance Taylor
  2011-01-08  5:11   ` Daniel Mierswa
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2011-01-08  4:50 UTC (permalink / raw)
  To: Daniel Mierswa; +Cc: gcc-help

Daniel Mierswa <impulze@impulze.org> writes:

> I was wondering which registers I have to clobber or which special
> strings I have to put into the clobber list if all I'm going to do is:
>
> asm("call %0;" ::"m"(addr_of_myfunc));
>
> As I can't tell what the function is doing I may have to clobber all
> registers or am I wrong?
> I had in mind to clobber "cc" plus "eax", "ecx", "edx" which are by the
> i386 ABI not preserved for the caller.

You are correct: you have to list all the caller-saved registers in the
clobber list.  On 32-bit x86 this is all the registers other than %ebp,
%ebx, %edi and %esi.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: clobber list in inline assembly for calls
  2011-01-08  4:50 ` Ian Lance Taylor
@ 2011-01-08  5:11   ` Daniel Mierswa
  2011-01-08  5:24     ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mierswa @ 2011-01-08  5:11 UTC (permalink / raw)
  To: gcc-help

On 08.01.2011 05:50, Ian Lance Taylor wrote:
> You are correct: you have to list all the caller-saved registers in the
> clobber list.  On 32-bit x86 this is all the registers other than %ebp,
> %ebx, %edi and %esi.
> 
> Ian

If I'm not mistaken that should leave eax, ecx and edx. What about "cc"
and "memory" though?

-- 
Mierswa, Daniel

If you still don't like it, that's ok: that's why I'm boss. I simply
know better than you do.
               --- Linus Torvalds, comp.os.linux.advocacy, 1996/07/22

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: clobber list in inline assembly for calls
  2011-01-08  5:11   ` Daniel Mierswa
@ 2011-01-08  5:24     ` Ian Lance Taylor
  2011-01-08  5:43       ` Daniel Mierswa
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2011-01-08  5:24 UTC (permalink / raw)
  To: Daniel Mierswa; +Cc: gcc-help

Daniel Mierswa <impulze@impulze.org> writes:

> On 08.01.2011 05:50, Ian Lance Taylor wrote:
>> You are correct: you have to list all the caller-saved registers in the
>> clobber list.  On 32-bit x86 this is all the registers other than %ebp,
>> %ebx, %edi and %esi.
>> 
>> Ian
>
> If I'm not mistaken that should leave eax, ecx and edx. What about "cc"
> and "memory" though?

Good point, yes, you should add an explicit "memory" clobber.  You don't
need to explicitly clobber "cc".  That is a fixed register (actually gcc
calls it "flags") and as such gcc won't make any particular assumptions
about it in any case.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: clobber list in inline assembly for calls
  2011-01-08  5:24     ` Ian Lance Taylor
@ 2011-01-08  5:43       ` Daniel Mierswa
  2011-01-08 18:52         ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mierswa @ 2011-01-08  5:43 UTC (permalink / raw)
  To: gcc-help

On 08.01.2011 06:23, Ian Lance Taylor wrote:
> Good point, yes, you should add an explicit "memory" clobber.  You don't
> need to explicitly clobber "cc".  That is a fixed register (actually gcc
> calls it "flags") and as such gcc won't make any particular assumptions
> about it in any case.
> 
> Ian

Ok I'm curious as to why.

If the information at
http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss5.3 is
of any use then I'd have to:

[...]
If our instruction can alter the condition code register, we have to add
"cc" to the list of clobbered registers.

If our instruction modifies memory in an unpredictable fashion, add
"memory" to the list of clobbered registers.
[...]

I don't know if any of both situations may happen in my called function,
hence I'd have to supply both, or am I wrong?

-- 
Mierswa, Daniel

If you still don't like it, that's ok: that's why I'm boss. I simply
know better than you do.
               --- Linus Torvalds, comp.os.linux.advocacy, 1996/07/22

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: clobber list in inline assembly for calls
  2011-01-08  5:43       ` Daniel Mierswa
@ 2011-01-08 18:52         ` Ian Lance Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 2011-01-08 18:52 UTC (permalink / raw)
  To: Daniel Mierswa; +Cc: gcc-help

Daniel Mierswa <impulze@impulze.org> writes:

> On 08.01.2011 06:23, Ian Lance Taylor wrote:
>> Good point, yes, you should add an explicit "memory" clobber.  You don't
>> need to explicitly clobber "cc".  That is a fixed register (actually gcc
>> calls it "flags") and as such gcc won't make any particular assumptions
>> about it in any case.
>> 
>> Ian
>
> Ok I'm curious as to why.
>
> If the information at
> http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss5.3 is
> of any use then I'd have to:
>
> [...]
> If our instruction can alter the condition code register, we have to add
> "cc" to the list of clobbered registers.
>
> If our instruction modifies memory in an unpredictable fashion, add
> "memory" to the list of clobbered registers.
> [...]
>
> I don't know if any of both situations may happen in my called function,
> hence I'd have to supply both, or am I wrong?

You can add a clobber of "cc" if you like, it just won't make any
difference one way or another.  On x86 gcc already assumes that the
flags are clobbered by an asm.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-01-08 18:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-08  0:31 clobber list in inline assembly for calls Daniel Mierswa
2011-01-08  4:50 ` Ian Lance Taylor
2011-01-08  5:11   ` Daniel Mierswa
2011-01-08  5:24     ` Ian Lance Taylor
2011-01-08  5:43       ` Daniel Mierswa
2011-01-08 18:52         ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).