Patchwork [committed] Update config/pa/linux-atomic.c and enable sync tests on hppa-linux

login
register
mail settings
Submitter John David Anglin
Date Oct. 11, 2010, 9:42 p.m.
Message ID <20101011214203.GA279@hiauly1.hia.nrc.ca>
Download mbox | patch
Permalink /patch/67486/
State New
Headers show

Comments

John David Anglin - Oct. 11, 2010, 9:42 p.m.
On Wed, 11 Aug 2010, Richard Henderson wrote:

> FWIW, I had a browse through this file and it's a bit off.  E.g.:
> 
> > __sync_val_compare_and_swap_4 (int *ptr, int oldval, int newval)
> > {
> >   int actual_oldval, fail;
> >     
> >   while (1)
> >     {
> >       actual_oldval = *ptr;
> > 
> >       if (oldval != actual_oldval)
> >         return actual_oldval;
> > 
> >       fail = __kernel_cmpxchg (actual_oldval, newval, ptr);
> >   
> >       if (!fail)
> >         return oldval;
> >     }
> > }
> 
> This should not be returning the OLDVAL that the user passed,
> it should be returning the lws_ret that the kernel returned.
> 
> This is because the user of __sync_val_c_a_s wants avoid the
> reload of the value, like so (from libgomp/iter.c):

I adjusted the returns per your suggestion.  Does this look right?

I have had this in my hppa-linux build trees for some time and haven't
seen and regressions.

Thanks for looking over the original patch.

Dave
Richard Henderson - Oct. 11, 2010, 10:31 p.m.
On 10/11/2010 02:42 PM, John David Anglin wrote:
> I adjusted the returns per your suggestion.  Does this look right?

Looks good.


r~

Patch

Index: config/pa/linux-atomic.c
===================================================================
--- config/pa/linux-atomic.c	(revision 164230)
+++ config/pa/linux-atomic.c	(working copy)
@@ -191,13 +191,13 @@ 
     {
       actual_oldval = *ptr;
 
-      if (oldval != actual_oldval)
+      if (__builtin_expect (oldval != actual_oldval, 0))
 	return actual_oldval;
 
       fail = __kernel_cmpxchg (actual_oldval, newval, ptr);
   
-      if (!fail)
-	return oldval;
+      if (__builtin_expect (!fail, 1))
+	return actual_oldval;
     }
 }
 
@@ -216,8 +216,9 @@ 
       {									\
 	actual_oldval = *wordptr;					\
 									\
-	if (((actual_oldval & mask) >> shift) != (unsigned int) oldval)	\
-          return (actual_oldval & mask) >> shift;			\
+	if (__builtin_expect (((actual_oldval & mask) >> shift)		\
+			      != (unsigned int) oldval, 0))		\
+	  return (actual_oldval & mask) >> shift;			\
 									\
 	actual_newval = (actual_oldval & ~mask)				\
 			| (((unsigned int) newval << shift) & mask);	\
@@ -225,8 +226,8 @@ 
 	fail = __kernel_cmpxchg (actual_oldval, actual_newval,		\
 				 wordptr);				\
 									\
-	if (!fail)							\
-	  return oldval;						\
+	if (__builtin_expect (!fail, 1))				\
+	  return (actual_oldval & mask) >> shift;			\
       }									\
   }