[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#654630: Please review this diff for atomic ops in mesa on m68k



Dear m68k porters,

mesa FTBFS on m68k due to lack of GCC atomic intrinsics. (Why are
they (still) missing, anyway?) I’ve had a look at other patches
floating around on this mailing list and drafted the attached diff
which makes it at least compile again. My knowledge is not enough
to validate that this DTRT, especially where multi-threaded pro‐
gramming is involved, so please look it over.

At first I wanted to use libatomic-ops-dev, but since Gallium hard‐
codes the use of pointers to int32_t, it wasn’t feasible without
touching large parts of the code, hence the m68k-specific fix, as
seems to have been tradition in several places.

bye,
//mirabilos, who’s currently pretty busy with daylife ☹
-- 
  “Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool.”
						-- Edward Burr
diff -Nru mesa-7.11.2/debian/changelog mesa-7.11.2/debian/changelog
--- mesa-7.11.2/debian/changelog	2012-01-10 08:48:31.000000000 +0000
+++ mesa-7.11.2/debian/changelog	2012-01-10 08:49:40.000000000 +0000
@@ -1,3 +1,9 @@
+mesa (7.11.2-1+m68k.1) unreleased; urgency=low
+
+  * Add atomic operations for m68k. (Closes: #654630)
+
+ -- Thorsten Glaser <tg@mirbsd.de>  Sun, 08 Jan 2012 17:23:47 +0000
+
 mesa (7.11.2-1) unstable; urgency=low
 
   * New upstream release:
diff -Nru mesa-7.11.2/debian/patches/15-m68k-atomic-ops.diff mesa-7.11.2/debian/patches/15-m68k-atomic-ops.diff
--- mesa-7.11.2/debian/patches/15-m68k-atomic-ops.diff	1970-01-01 00:00:00.000000000 +0000
+++ mesa-7.11.2/debian/patches/15-m68k-atomic-ops.diff	2012-01-10 08:49:40.000000000 +0000
@@ -0,0 +1,90 @@
+Index: mesa-7.11.2/src/gallium/auxiliary/util/u_atomic.h
+===================================================================
+--- mesa-7.11.2.orig/src/gallium/auxiliary/util/u_atomic.h	2012-01-08 17:41:45.000000000 +0000
++++ mesa-7.11.2/src/gallium/auxiliary/util/u_atomic.h	2012-01-08 21:09:19.000000000 +0000
+@@ -31,6 +31,9 @@
+ #define PIPE_ATOMIC_ASM_GCC_X86
+ #elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64))
+ #define PIPE_ATOMIC_ASM_GCC_X86_64
++#elif (defined(PIPE_CC_GCC) && defined(__m68k__))
++/* hopefully 68020 or better, Linux */
++#define PIPE_ATOMIC_ASM_GCC_M68K
+ #elif defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 401)
+ #define PIPE_ATOMIC_GCC_INTRINSIC
+ #else
+@@ -343,6 +346,75 @@
+ #endif
+ 
+ 
++#if defined(PIPE_ATOMIC_ASM_GCC_M68K)
++#define PIPE_ATOMIC "GCC m68k assembly"
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++
++#define p_atomic_set(_v, _i) (*(_v) = (_i))
++#define p_atomic_read(_v) (*(_v))
++
++#define p_atomic_m68k_cmpxchg(p, old, new, dst)			\
++	__asm__ __volatile__("casl %0,%2,%1"			\
++			     : "=d" (dst), "=m" (*p)		\
++			     : "d" (new), "0" (old), "m" (*p))
++
++static INLINE int32_t
++p_atomic_m68k_add_and_fetch(int32_t *v, int32_t i)
++{
++   int32_t prev, next;
++
++   for (;;) {
++      prev = *v;
++      next = prev + i;
++      p_atomic_m68k_cmpxchg(v, prev, next, prev);
++      if (prev == next)
++         return next;
++   }
++}
++
++static INLINE boolean
++p_atomic_dec_zero(int32_t *v)
++{
++   return (p_atomic_m68k_add_and_fetch(v, (int32_t)-1) == 0);
++}
++
++static INLINE void
++p_atomic_inc(int32_t *v)
++{
++   p_atomic_m68k_add_and_fetch(v, 1);
++}
++
++static INLINE void
++p_atomic_dec(int32_t *v)
++{
++   p_atomic_m68k_add_and_fetch(v, (int32_t)-1);
++}
++
++static INLINE int32_t
++p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
++{
++   int32_t prev, dest;
++
++   for (;;) {
++      prev = *v;
++      if (prev != old)
++         return prev;
++      p_atomic_m68k_cmpxchg(v, prev, _new, dest);
++      if (dest == _new)
++         return prev;
++   }
++}
++
++#ifdef __cplusplus
++}
++#endif
++
++#endif /* PIPE_ATOMIC_ASM_GCC_M68K */
++
++
+ #ifndef PIPE_ATOMIC
+ #error "No pipe_atomic implementation selected"
+ #endif
diff -Nru mesa-7.11.2/debian/patches/series mesa-7.11.2/debian/patches/series
--- mesa-7.11.2/debian/patches/series	2012-01-10 08:48:31.000000000 +0000
+++ mesa-7.11.2/debian/patches/series	2012-01-10 08:49:40.000000000 +0000
@@ -7,3 +7,4 @@
 11-hurd-ftbfs-again.diff
 13-llvm-config-pick-a-version.diff
 14-load-swrastg-before-swrast.diff
+15-m68k-atomic-ops.diff

Reply to: