Memory Barrier [Q]

Jim Wilson wilson@tuliptree.org
Wed Jun 11 20:18:00 GMT 2003


Zach, Yoav wrote:
> Can someone help me with this question I have about gcc - How gcc treats
> the instruction 'asm("":::"memory")' ? 

For optimization purposes, it will act like a memory barrier.  The 
memory clobber means that it may change memory in unexplained ways. 
Also, an asm with no output is automatically volatile, and volatile 
means that it may change processor state in unexplained ways.

Thus the compiler will avoid optimizations that move instructions or 
values from memory across the asm.

See also the documentation in the gcc manual.
http://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Extended-Asm.html#Extended%20Asm

Jim



More information about the Gcc mailing list