asm ("") does nothing (or at least it should not do anything.
asm volatile ("") also does nothing.
asm ("" ::: "memory") is a simple compiler fence.
asm volatile ("" ::: "memory") AFAIK is similar to the previous one. The volatile keyword tells the compiler that it is not allowed to move this assembly block. For example, it may be loop-aligned if the compiler decides that the input values ββare the same for each call. I'm not sure under what conditions the compiler will decide that it understands the assembly enough to try to optimize its placement, but the volatile keyword completely blocks this. However, I would be very surprised if the compiler tried to move the asm statement that did not have the declared inputs or outputs.
By the way, volatile also prevents the compiler from deleting an expression if it decides that the output values ββare not used. This can only happen if there are output values, so it does not apply to asm ("" ::: "memory") .
Lily Ballard Jan 21 '13 at 23:41 2013-01-21 23:41
source share