Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Aug 2013 21:14:16 +0000 (UTC)
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r254612 - in head/sys: amd64/include i386/include
Message-ID:  <201308212114.r7LLEGrW099474@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jkim
Date: Wed Aug 21 21:14:16 2013
New Revision: 254612
URL: http://svnweb.freebsd.org/changeset/base/254612

Log:
  Use '+' modifier for a memory operand that is both an input and an output.
  It was actually done in r86301 but reverted in r150182 because GCC 3.x was
  not able to handle it for a memory operand.  Apparently, this problem was
  fixed in GCC 4.1+ and several contrib sources already rely on this feature.

Modified:
  head/sys/amd64/include/atomic.h
  head/sys/i386/include/atomic.h

Modified: head/sys/amd64/include/atomic.h
==============================================================================
--- head/sys/amd64/include/atomic.h	Wed Aug 21 20:49:46 2013	(r254611)
+++ head/sys/amd64/include/atomic.h	Wed Aug 21 21:14:16 2013	(r254612)
@@ -108,8 +108,8 @@ static __inline void					\
 atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
 	__asm __volatile(MPLOCKED OP			\
-	: "=m" (*p)					\
-	: CONS (V), "m" (*p)				\
+	: "+m" (*p)					\
+	: CONS (V)					\
 	: "cc");					\
 }							\
 							\
@@ -117,8 +117,8 @@ static __inline void					\
 atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
 	__asm __volatile(MPLOCKED OP			\
-	: "=m" (*p)					\
-	: CONS (V), "m" (*p)				\
+	: "+m" (*p)					\
+	: CONS (V)					\
 	: "memory", "cc");				\
 }							\
 struct __hack
@@ -142,10 +142,9 @@ atomic_cmpset_int(volatile u_int *dst, u
 	"       sete	%0 ;		"
 	"# atomic_cmpset_int"
 	: "=a" (res),			/* 0 */
-	  "=m" (*dst)			/* 1 */
+	  "+m" (*dst)			/* 1 */
 	: "r" (src),			/* 2 */
-	  "a" (expect),			/* 3 */
-	  "m" (*dst)			/* 4 */
+	  "a" (expect)			/* 3 */
 	: "memory", "cc");
 
 	return (res);
@@ -162,10 +161,9 @@ atomic_cmpset_long(volatile u_long *dst,
 	"       sete	%0 ;		"
 	"# atomic_cmpset_long"
 	: "=a" (res),			/* 0 */
-	  "=m" (*dst)			/* 1 */
+	  "+m" (*dst)			/* 1 */
 	: "r" (src),			/* 2 */
-	  "a" (expect),			/* 3 */
-	  "m" (*dst)			/* 4 */
+	  "a" (expect)			/* 3 */
 	: "memory", "cc");
 
 	return (res);
@@ -184,9 +182,8 @@ atomic_fetchadd_int(volatile u_int *p, u
 	"	xaddl	%0,%1 ;		"
 	"# atomic_fetchadd_int"
 	: "+r" (v),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "cc");
+	  "+m" (*p)			/* 1 */
+	: : "cc");
 	return (v);
 }
 
@@ -203,9 +200,8 @@ atomic_fetchadd_long(volatile u_long *p,
 	"	xaddq	%0,%1 ;		"
 	"# atomic_fetchadd_long"
 	: "+r" (v),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "cc");
+	  "+m" (*p)			/* 1 */
+	: : "cc");
 	return (v);
 }
 
@@ -253,9 +249,8 @@ atomic_load_acq_##TYPE(volatile u_##TYPE
 							\
 	__asm __volatile(MPLOCKED LOP			\
 	: "=a" (res),			/* 0 */		\
-	  "=m" (*p)			/* 1 */		\
-	: "m" (*p)			/* 2 */		\
-	: "memory", "cc");				\
+	  "+m" (*p)			/* 1 */		\
+	: : "memory", "cc");				\
 							\
 	return (res);					\
 }							\
@@ -314,8 +309,7 @@ atomic_readandclear_int(volatile u_int *
 	"	xchgl	%1,%0 ;		"
 	"# atomic_readandclear_int"
 	: "+r" (res),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p));
+	  "+m" (*p));			/* 1 */
 
 	return (res);
 }
@@ -330,8 +324,7 @@ atomic_readandclear_long(volatile u_long
 	"	xchgq	%1,%0 ;		"
 	"# atomic_readandclear_long"
 	: "+r" (res),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p));
+	  "+m" (*p));			/* 1 */
 
 	return (res);
 }

Modified: head/sys/i386/include/atomic.h
==============================================================================
--- head/sys/i386/include/atomic.h	Wed Aug 21 20:49:46 2013	(r254611)
+++ head/sys/i386/include/atomic.h	Wed Aug 21 21:14:16 2013	(r254612)
@@ -106,8 +106,8 @@ static __inline void					\
 atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
 	__asm __volatile(MPLOCKED OP			\
-	: "=m" (*p)					\
-	: CONS (V), "m" (*p)				\
+	: "+m" (*p)					\
+	: CONS (V)					\
 	: "cc");					\
 }							\
 							\
@@ -115,8 +115,8 @@ static __inline void					\
 atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
 	__asm __volatile(MPLOCKED OP			\
-	: "=m" (*p)					\
-	: CONS (V), "m" (*p)				\
+	: "+m" (*p)					\
+	: CONS (V)					\
 	: "memory", "cc");				\
 }							\
 struct __hack
@@ -174,11 +174,10 @@ atomic_load_acq_64_i586(volatile uint64_
 	"	movl %%ebx,%%eax ;	"
 	"	movl %%ecx,%%edx ;	"
 	"	" MPLOCKED "		"
-	"	cmpxchg8b %2"
+	"	cmpxchg8b %1"
 	: "=&A" (res),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "memory", "cc");
+	  "+m" (*p)			/* 1 */
+	: : "memory", "cc");
 
 	return (res);
 }
@@ -192,12 +191,11 @@ atomic_store_rel_64_i586(volatile uint64
 	"	movl %%edx,%%ecx ;	"
 	"1:				"
 	"	" MPLOCKED "		"
-	"	cmpxchg8b %2 ;		"
+	"	cmpxchg8b %0 ;		"
 	"	jne 1b"
-	: "=m" (*p),			/* 0 */
+	: "+m" (*p),			/* 0 */
 	  "+A" (v)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "ebx", "ecx", "memory", "cc");
+	: : "ebx", "ecx", "memory", "cc");
 }
 
 #endif /* _KERNEL && !WANT_FUNCTIONS */
@@ -220,7 +218,7 @@ atomic_cmpset_int(volatile u_int *dst, u
 	__asm __volatile(
 	"	pushfl ;		"
 	"	cli ;			"
-	"	cmpl	%3,%4 ;		"
+	"	cmpl	%3,%1 ;		"
 	"	jne	1f ;		"
 	"	movl	%2,%1 ;		"
 	"1:				"
@@ -228,10 +226,9 @@ atomic_cmpset_int(volatile u_int *dst, u
 	"	popfl ;			"
 	"# atomic_cmpset_int"
 	: "=q" (res),			/* 0 */
-	  "=m" (*dst)			/* 1 */
+	  "+m" (*dst)			/* 1 */
 	: "r" (src),			/* 2 */
-	  "r" (expect),			/* 3 */
-	  "m" (*dst)			/* 4 */
+	  "r" (expect)			/* 3 */
 	: "memory");
 
 	return (res);
@@ -250,10 +247,9 @@ atomic_cmpset_int(volatile u_int *dst, u
 	"       sete	%0 ;		"
 	"# atomic_cmpset_int"
 	: "=a" (res),			/* 0 */
-	  "=m" (*dst)			/* 1 */
+	  "+m" (*dst)			/* 1 */
 	: "r" (src),			/* 2 */
-	  "a" (expect),			/* 3 */
-	  "m" (*dst)			/* 4 */
+	  "a" (expect)			/* 3 */
 	: "memory", "cc");
 
 	return (res);
@@ -274,9 +270,8 @@ atomic_fetchadd_int(volatile u_int *p, u
 	"	xaddl	%0,%1 ;		"
 	"# atomic_fetchadd_int"
 	: "+r" (v),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "cc");
+	  "+m" (*p)			/* 1 */
+	: : "cc");
 	return (v);
 }
 
@@ -324,9 +319,8 @@ atomic_load_acq_##TYPE(volatile u_##TYPE
 							\
 	__asm __volatile(MPLOCKED LOP			\
 	: "=a" (res),			/* 0 */		\
-	  "=m" (*p)			/* 1 */		\
-	: "m" (*p)			/* 2 */		\
-	: "memory", "cc");				\
+	  "+m" (*p)			/* 1 */		\
+	: : "memory", "cc");				\
 							\
 	return (res);					\
 }							\
@@ -405,8 +399,7 @@ atomic_readandclear_int(volatile u_int *
 	"	xchgl	%1,%0 ;		"
 	"# atomic_readandclear_int"
 	: "+r" (res),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p));
+	  "+m" (*p));			/* 1 */
 
 	return (res);
 }
@@ -421,8 +414,7 @@ atomic_readandclear_long(volatile u_long
 	"	xchgl	%1,%0 ;		"
 	"# atomic_readandclear_long"
 	: "+r" (res),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p));
+	  "+m" (*p));			/* 1 */
 
 	return (res);
 }



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