fix-asm
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Fri, 6 May 2011 13:52:41 +0000 (14:52 +0100)
committerAdam C. Powell, IV <hazelsct@debian.org>
Fri, 6 May 2011 13:52:41 +0000 (14:52 +0100)
Replace x86 assembly code by atomic extensions provided by GNU g++.
(closes: #518837)

Submitted upstream: http://www.opencascade.org/org/forum/thread_20053/

Gbp-Pq: Topic submitted
Gbp-Pq: Name fix-asm.patch

ros/inc/Standard_Atomic.hxx
ros/src/Standard/Standard_Atomic.hxx

index 93f80ecd84e16dde7d96ce647fbdd465ee2bec7d..ce9c8102bc1a02366340dee1daa15d57d34b8909 100644 (file)
@@ -45,13 +45,13 @@ inline int Standard_Atomic_DecrementTest (int volatile* var)
 }
 
 //===================================================
-// Linux, GCC compiler
+// GCC compiler on x86 or x86_64
 // Note: Linux kernel 2.6x provides definitions for atomic operators
 //       in the header file /usr/include/asm/atomic.h,
 //       however these definitions involve specific type atomic_t
 // Note: The same code probably would work for Intel compiler
 //===================================================
-#elif defined(LIN)
+#elif defined(__GNUG__) && (defined(__i386) || defined(__x86_64))
 
 inline void Standard_Atomic_Increment (int volatile* var)
 {
@@ -82,6 +82,30 @@ inline int Standard_Atomic_DecrementTest (int volatile* var)
   return c != 0;
 }
 
+//===================================================
+// GCC extension for atomic operations
+// http://gcc.gnu.org/wiki/Atomic
+//===================================================
+#elif defined(__GNUG__) && !defined(__sparc_v9) && !defined(__sparc_v9__) // _Atomic_word is not an int on SPARC V9
+
+#include <ext/atomicity.h>
+
+inline void Standard_Atomic_Increment (int* var)
+{
+  // C equivalent:
+  // ++(*var);
+
+  __gnu_cxx::__atomic_add_dispatch(static_cast<_Atomic_word*>(var), 1);
+}
+
+inline int Standard_Atomic_DecrementTest (int* var)
+{
+  // C equivalent:
+  // return --(*var) == 0;
+
+  return __gnu_cxx::__exchange_and_add_dispatch(static_cast<_Atomic_word*>(var),-1) == 1;
+}
+
 //===================================================
 // Default stub implementation, not atomic actually
 //===================================================
index 93f80ecd84e16dde7d96ce647fbdd465ee2bec7d..ce9c8102bc1a02366340dee1daa15d57d34b8909 100644 (file)
@@ -45,13 +45,13 @@ inline int Standard_Atomic_DecrementTest (int volatile* var)
 }
 
 //===================================================
-// Linux, GCC compiler
+// GCC compiler on x86 or x86_64
 // Note: Linux kernel 2.6x provides definitions for atomic operators
 //       in the header file /usr/include/asm/atomic.h,
 //       however these definitions involve specific type atomic_t
 // Note: The same code probably would work for Intel compiler
 //===================================================
-#elif defined(LIN)
+#elif defined(__GNUG__) && (defined(__i386) || defined(__x86_64))
 
 inline void Standard_Atomic_Increment (int volatile* var)
 {
@@ -82,6 +82,30 @@ inline int Standard_Atomic_DecrementTest (int volatile* var)
   return c != 0;
 }
 
+//===================================================
+// GCC extension for atomic operations
+// http://gcc.gnu.org/wiki/Atomic
+//===================================================
+#elif defined(__GNUG__) && !defined(__sparc_v9) && !defined(__sparc_v9__) // _Atomic_word is not an int on SPARC V9
+
+#include <ext/atomicity.h>
+
+inline void Standard_Atomic_Increment (int* var)
+{
+  // C equivalent:
+  // ++(*var);
+
+  __gnu_cxx::__atomic_add_dispatch(static_cast<_Atomic_word*>(var), 1);
+}
+
+inline int Standard_Atomic_DecrementTest (int* var)
+{
+  // C equivalent:
+  // return --(*var) == 0;
+
+  return __gnu_cxx::__exchange_and_add_dispatch(static_cast<_Atomic_word*>(var),-1) == 1;
+}
+
 //===================================================
 // Default stub implementation, not atomic actually
 //===================================================