Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - __cpu_membarrier again :): (2 Items)
   
__cpu_membarrier again :)  
I have the following link I use to consult when I need to remember anything regarding inline assembler.
http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
I can't guarrantee it's completely correct but there is the following phrase in it: "If our instruction can alter the 
condition code register, we have to add "cc" to the list of clobbered registers.". This means that if assembler block 
modifies EFLAGS (or similar registers on other architectures) "cc" needs to be added to clobber list.
Now the question is: does not the __cpu_membarrier() implementation (which is citated below) lack "cc" in clobber list?

#define __cpu_membarrier()                                              \
    ({                                                                  \
        extern unsigned __cpu_flags;                                    \
        /* check for X86_CPU_SSE2 */                                    \
        if (__cpu_flags & (1 << 15)) {                                  \
            __asm__ __volatile__ ("mfence");                            \
        } else {                                                        \
            __asm__ __volatile__ ("lock; orb $0,0(%esp)");              \
        }                                                               \
    })
Re: __cpu_membarrier again :)  
Well, actually I suppose "cc" is not necessary here as volatile should prevent the compiler from splitting logic of 
other actions across the assembler block. Though, it's really hard to find any official documentation on inline 
assembler in GCC :(.