Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Oct 2004 20:23:05 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 63381 for review
Message-ID:  <200410192023.i9JKN5Na092746@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=63381

Change 63381 by jhb@jhb_tibook on 2004/10/19 20:22:10

	Use fences on amd64 for memory barriers (untested).

Affected files ...

.. //depot/projects/smpng/sys/amd64/include/atomic.h#4 edit

Differences ...

==== //depot/projects/smpng/sys/amd64/include/atomic.h#4 (text+ko) ====

@@ -162,30 +162,22 @@
 
 #if defined(__GNUC__)
 
-#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP)		\
+#define ATOMIC_STORE_LOAD(TYPE)				\
 static __inline u_##TYPE				\
 atomic_load_acq_##TYPE(volatile u_##TYPE *p)		\
 {							\
-	u_##TYPE res;					\
+	u_##TYPE v;					\
 							\
-	__asm __volatile(__XSTRING(MPLOCKED) LOP	\
-	: "=a" (res),			/* 0 (result) */\
-	  "+m" (*p)			/* 1 */		\
-	: : "memory");				 	\
-							\
-	return (res);					\
+	v = *p;						\
+	__asm __volatile("lfence" ::: "memory");	\
+	return (v);					\
 }							\
 							\
-/*							\
- * The XCHG instruction asserts LOCK automagically.	\
- */							\
 static __inline void					\
 atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
-	__asm __volatile(SOP				\
-	: "+m" (*p),			/* 0 */		\
-	  "+r" (v)			/* 1 */		\
-	: : "memory");				 	\
+	__asm __volatile("sfence" ::: "memory");	\
+	*p = v;						\
 }							\
 struct __hack
 
@@ -194,7 +186,7 @@
 extern int atomic_cmpset_int(volatile u_int *, u_int, u_int);
 extern int atomic_cmpset_long(volatile u_long *, u_long, u_long);
 
-#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP)				\
+#define ATOMIC_STORE_LOAD(TYPE)						\
 extern u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p);		\
 extern void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
 
@@ -222,10 +214,10 @@
 ATOMIC_ASM(add,	     long,  "addq %1,%0",  "ir",  v);
 ATOMIC_ASM(subtract, long,  "subq %1,%0",  "ir",  v);
 
-ATOMIC_STORE_LOAD(char,	"cmpxchgb %b0,%1", "xchgb %b1,%0");
-ATOMIC_STORE_LOAD(short,"cmpxchgw %w0,%1", "xchgw %w1,%0");
-ATOMIC_STORE_LOAD(int,	"cmpxchgl %0,%1",  "xchgl %1,%0");
-ATOMIC_STORE_LOAD(long,	"cmpxchgq %0,%1",  "xchgq %1,%0");
+ATOMIC_STORE_LOAD(char);
+ATOMIC_STORE_LOAD(short);
+ATOMIC_STORE_LOAD(int);
+ATOMIC_STORE_LOAD(long);
 
 #undef ATOMIC_ASM
 #undef ATOMIC_STORE_LOAD



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200410192023.i9JKN5Na092746>