This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Inline Assembly queries


kernel mailz <kernelmailz@googlemail.com> writes:

> I've been fiddling my luck with gcc 4.3.2 inline assembly on powerpc
> There are a few queries
>
> 1. asm volatile or simply asm produce the same assembly code.
> Tried with a few examples but didnt find any difference by adding
> volatile with asm
>
> 2. Use of "memory" and clobbered registers.
>
> "memory" -
> a. announce to the compiler that the memory has been modified
> b. this instruction writes to some memory (other than a listed output)
> and GCC shouldnât cache memory values in registers across this asm.
>
> I tried with stw and stwcx instruction, adding "memory" has no effect.
>
> Is there any example scenerio where gcc would generate different
> assembly by adding / removing "memory" ?

Please never send a message to both gcc@gcc.gnu.org and
gcc-help@gcc.gnu.org.  This message is appropriate for
gcc-help@gcc.gnu.org, not for gcc@gcc.gnu.org.  Thanks.

An asm with no outputs is always considered to be volatile.  To see the
affect of volatile, just try something like
    asm ("# modify %0" : "=r" (i) : /* no inputs */ : /* no clobbers */);
Try it with and without optimization.

As the documentation says, the effect of adding a "memory" clobber is
that gcc does not cache values in registers across the asm.  So the
effect will be shown in something like
  int i = *p;
  asm volatile ("# read %0" : : "r" (i));
  return *p;
The memory clobber will only make a different when optimizing.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]