public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* clobbering input args in inline asm
@ 2006-04-28 22:35 Stas Sergeev
  2006-04-29  8:51 ` Andrew Haley
  0 siblings, 1 reply; 6+ messages in thread
From: Stas Sergeev @ 2006-04-28 22:35 UTC (permalink / raw)
  To: gcc-help

Hi.

As probably many of the new gcc users, I stumbled over
the fact that gcc allows an inline asm to modify the
input arguments, and there seem to be no other way
of preventing that, than to use the dummy output var.
And, just as all the others who stumbled over this, I
found that solution counter-intuitive. So I tried some
other things, and now I have a few questions.
Below is the program that prints the different results
when compiled with -O0 and -O2, and the fact that the
asm constraints are broken, is really counter-intuitive,
IMHO.

My questions are:
- I can't add the register both in the input list and the
clobber list, and that's perfectly documented. However, it
seems like I can add "0" in the clobber list, and gcc accepts
that. Though, it still doesn't give the right code. I wasn't
able to find in the gcc manual, nor in the google, what will
the "0" mean in the clobber list - so what is it?
- Another strange thing is that I can add "0" in the clobber
list if it refers to any of the register classes (on i386
target), but not to "a". I.e. if I have "b" in input and "0"
in clobber - gcc eats that. If I have "a" in input and "0"
in clobber - gcc complains. What is the reason?
- Why wouldn't gcc just allow the "&" modifier in the
input list? Just like in the output list it means early-clobber,
in the input list it could mean late-clobber, i.e. clobbered
after the value was taken.

Sorry for the novice questions. This is mainly just my curiosity
and the fact that I find an official solution very confusing and
counter-intuitive.

Thanks for any info.


The test-case:
---
#include <stdio.h>

volatile int a = 5;

int main()
{
  int b = a;
  asm volatile ("movl $0, %%ebx\n" :: "b"(b));
  printf("%i\n", b);
  return 0;
}
---
Prints 5 when compiled with -O0, and 0 when compiled with -O1.

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

end of thread, other threads:[~2006-05-02 19:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-28 22:35 clobbering input args in inline asm Stas Sergeev
2006-04-29  8:51 ` Andrew Haley
2006-04-29  9:44   ` Stas Sergeev
2006-05-02 10:44     ` Andrew Haley
2006-05-02 19:21       ` Stas Sergeev
2006-05-02 19:53         ` Andrew Haley

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).