On Thu, Nov 01, 2012 at 09:25:53AM +0100, Joerg-Cyril.Hoehle@t-systems.com wrote:
Background: I want an atomic read of whatever value a single aligned int (or DOWRD or whatever) currently appears visible to one core.
A simple read of a volatile data item will do that. Look at what signal handlers are allowed to change.
New compilers link clang support the gcc asm semantics - they need to in order to compile a lot of their target code.
The purpose of 'asm volatile ("":::""memory);' is to constrain the values that the compiler can have cached in registers.
I use it for 3 purposes: 1) To ensure object code accesses memory in the correct order (provided the cpu can't reorder the memory accesses itself (which many modern cpu will do - at least for cached accesses). 2) To reduce the number 'live' values in a function to stop values being spilled to stack. 3) To force the generated code to read values early (sometimes before an 'if' when the value is only used in one clause) in order to remove cpu stalls waiting for memory and to fill otherwise unfillable delay slots. This one is very cpu specific - but I am counting every instruction in that function. (This is a MIPS-like embedded cpu.)
David