Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Sep 2019 01:39:58 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r352667 - head/sys/powerpc/include
Message-ID:  <201909250139.x8P1dw15098431@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhibbits
Date: Wed Sep 25 01:39:58 2019
New Revision: 352667
URL: https://svnweb.freebsd.org/changeset/base/352667

Log:
  powerpc/atomic: Follow recommendations on atomic primitive comparisons
  
  Both IBM and Freescale programming examples presume the cmpset operands will
  favor equal, and pessimize the non-equal case instead.  Do the same for
  atomic_cmpset_* and atomic_fcmpset_*.  This slightly pessimizes the failure
  case, in favor of the success case.
  
  MFC after:	3 weeks

Modified:
  head/sys/powerpc/include/atomic.h

Modified: head/sys/powerpc/include/atomic.h
==============================================================================
--- head/sys/powerpc/include/atomic.h	Wed Sep 25 01:23:08 2019	(r352666)
+++ head/sys/powerpc/include/atomic.h	Wed Sep 25 01:39:58 2019	(r352667)
@@ -568,7 +568,7 @@ atomic_cmpset_int(volatile u_int* p, u_int cmpval, u_i
 	__asm __volatile (
 		"1:\tlwarx %0, 0, %2\n\t"	/* load old value */
 		"cmplw %3, %0\n\t"		/* compare */
-		"bne 2f\n\t"			/* exit if not equal */
+		"bne- 2f\n\t"			/* exit if not equal */
 		"stwcx. %4, 0, %2\n\t"      	/* attempt to store */
 		"bne- 1b\n\t"			/* spin if failed */
 		"li %0, 1\n\t"			/* success - retval = 1 */
@@ -592,12 +592,12 @@ atomic_cmpset_long(volatile u_long* p, u_long cmpval, 
 	    #ifdef __powerpc64__
 		"1:\tldarx %0, 0, %2\n\t"	/* load old value */
 		"cmpld %3, %0\n\t"		/* compare */
-		"bne 2f\n\t"			/* exit if not equal */
+		"bne- 2f\n\t"			/* exit if not equal */
 		"stdcx. %4, 0, %2\n\t"		/* attempt to store */
 	    #else
 		"1:\tlwarx %0, 0, %2\n\t"	/* load old value */
 		"cmplw %3, %0\n\t"		/* compare */
-		"bne 2f\n\t"			/* exit if not equal */
+		"bne- 2f\n\t"			/* exit if not equal */
 		"stwcx. %4, 0, %2\n\t"		/* attempt to store */
 	    #endif
 		"bne- 1b\n\t"			/* spin if failed */
@@ -684,7 +684,7 @@ atomic_fcmpset_int(volatile u_int *p, u_int *cmpval, u
 	__asm __volatile (
 		"lwarx %0, 0, %3\n\t"	/* load old value */
 		"cmplw %4, %0\n\t"		/* compare */
-		"bne 1f\n\t"			/* exit if not equal */
+		"bne- 1f\n\t"			/* exit if not equal */
 		"stwcx. %5, 0, %3\n\t"      	/* attempt to store */
 		"bne- 1f\n\t"			/* exit if failed */
 		"li %0, 1\n\t"			/* success - retval = 1 */
@@ -709,12 +709,12 @@ atomic_fcmpset_long(volatile u_long *p, u_long *cmpval
 	    #ifdef __powerpc64__
 		"ldarx %0, 0, %3\n\t"	/* load old value */
 		"cmpld %4, %0\n\t"		/* compare */
-		"bne 1f\n\t"			/* exit if not equal */
+		"bne- 1f\n\t"			/* exit if not equal */
 		"stdcx. %5, 0, %3\n\t"		/* attempt to store */
 	    #else
 		"lwarx %0, 0, %3\n\t"	/* load old value */
 		"cmplw %4, %0\n\t"		/* compare */
-		"bne 1f\n\t"			/* exit if not equal */
+		"bne- 1f\n\t"			/* exit if not equal */
 		"stwcx. %5, 0, %3\n\t"		/* attempt to store */
 	    #endif
 		"bne- 1f\n\t"			/* exit if failed */



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