[PATCH] PR target/66224 _GLIBC_READ_MEM_BARRIER

David Edelsohn dje.gcc@gmail.com
Wed May 20 19:00:00 GMT 2015


The current definition of _GLIBC_READ_MEM_BARRIER in libstdc++ is too
weak for an ACQUIRE FENCE, which is what it is intended to be. The
original code emitted an "isync" instead of "lwsync".

All of the guard acquire and set code needs to be cleaned up to use
GCC atomic intrinsics, but this is necessary for correctness.

Steve, any comment about the Linux part?

- David

        PR target/66224
        * config/os/aix/atomic_word.h (_GLIBCXX_READ_MEM_BARRIER): Use
        lwsync if available, not isync.
        (_GLIBCXX_WRITE_MEM_BARRIER): Use lwsync if available.
        * config/cpu/powerpc/atomic_word.h (_GLIBCXX_READ_MEM_BARRIER):
        Use lwsync if available, not isync.

Index: config/os/aix/atomic_word.h
===================================================================
--- config/os/aix/atomic_word.h (revision 223444)
+++ config/os/aix/atomic_word.h (working copy)
@@ -33,9 +33,16 @@
 typedef int _Atomic_word;

 #ifdef _ARCH_PPC
-#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("isync":::"memory")
+
+#ifdef __NO_LWSYNC__
+#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("sync":::"memory")
 #define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("sync":::"memory")
 #else
+#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("lwsync":::"memory")
+#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("lwsync":::"memory")
+#endif
+
+#else
 #define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("":::"memory")
 #define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("":::"memory")
 #endif
Index: config/cpu/powerpc/atomic_word.h
===================================================================
--- config/cpu/powerpc/atomic_word.h    (revision 223444)
+++ config/cpu/powerpc/atomic_word.h    (working copy)
@@ -27,10 +27,11 @@

 typedef int _Atomic_word;

-#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("isync":::"memory")
 #ifdef __NO_LWSYNC__
+#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("sync":::"memory")
 #define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("sync":::"memory")
 #else
+#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("lwsync":::"memory")
 #define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("lwsync":::"memory")
 #endif



More information about the Gcc-patches mailing list