[m-rev.] for review: workaround problems with mercury_atomic_ops and gcc -O0

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Oct 24 15:03:19 AEST 2007


For review by PeterW.

Estimated hours taken: 0.2
Branches: main

Avoid problems with some versions of gcc when compiling the runtime
atomic_ops module at -O0 in non low-level .par grades.

runtime/mercury_atomic_ops.[hc]:
 	Implement MR_compare_and_swap_word using the builtin gcc compare
 	and swap if it is available.  (In particular prefer this to the
 	handcoded assembler versions on x86 and x86_64.)

 	Only include the code in these modules if MR_LL_PARALLEL_CONJ
 	is defined.  This helps to avoid problems with gcc in grades
 	where atomic operations are not used.

Julien.

Index: mercury_atomic_ops.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_atomic_ops.c,v
retrieving revision 1.1
diff -u -r1.1 mercury_atomic_ops.c
--- mercury_atomic_ops.c	11 Oct 2007 12:18:03 -0000	1.1
+++ mercury_atomic_ops.c	24 Oct 2007 04:55:44 -0000
@@ -14,6 +14,8 @@
  #include "mercury_imp.h"
  #include "mercury_atomic_ops.h"

+#if defined(MR_LL_PARALLEL_CON)
+
  /*---------------------------------------------------------------------------*/
  /*
  ** Provide definitions for functions declared `extern inline'.
@@ -28,3 +30,5 @@
  	MR_COMPARE_AND_SWAP_WORD_BODY;
      }
  )
+
+#endif /* MR_LL_PARALLEL_CONJ */
Index: mercury_atomic_ops.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_atomic_ops.h,v
retrieving revision 1.1
diff -u -r1.1 mercury_atomic_ops.h
--- mercury_atomic_ops.h	11 Oct 2007 12:18:03 -0000	1.1
+++ mercury_atomic_ops.h	24 Oct 2007 04:54:58 -0000
@@ -16,6 +16,8 @@

  #include "mercury_std.h"

+#if defined(MR_LL_PARALLEL_CON)
+
  /*
  ** If the value at addr is equal to old, assign new to addr and return true.
  ** Otherwise return false.
@@ -26,7 +28,17 @@

  /*---------------------------------------------------------------------------*/

-#if defined(__GNUC__) && defined(__x86_64__)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+
+    /*
+    ** gcc 4.1 and above have builtin atomic operations.
+    */
+    #define MR_COMPARE_AND_SWAP_WORD_BODY                                   \
+        do {                                                                \
+            return __sync_bool_compare_and_swap(addr, old, new_val);        \
+        } while (0)
+
+#elif defined(__GNUC__) && defined(__x86_64__)

      #define MR_COMPARE_AND_SWAP_WORD_BODY                                   \
          do {                                                                \
@@ -56,15 +68,6 @@
              return (int) result;                                            \
          } while (0)

-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
-
-    /* gcc 4.1 and above have builtin atomic operations. */
-
-    #define MR_COMPARE_AND_SWAP_WORD_BODY                                   \
-        do {                                                                \
-            return __sync_bool_compare_and_swap(addr, old, new_val);        \
-        } while (0)
-
  #endif

  #ifdef MR_COMPARE_AND_SWAP_WORD_BODY
@@ -82,4 +85,5 @@
  ** currently require any atomic ops.
  */

+#endif /* MR_LL_PARALLEL_CONJ */
  #endif /* not MERCURY_ATOMIC_OPS_H */


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list