[ported from trunk r165339, adjusted to apply to linux-atomic.c in config/m68k/; the __builtin_expect change is excluded ] Date: Mon, 11 Oct 2010 17:42:04 -0400 From: John David Anglin Subject: Re: [committed] Update config/pa/linux-atomic.c and enable sync tests on hppa-linux List-Archive: 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 -- J. David Anglin dave.anglin@nrc-cnrc.gc.ca National Research Council of Canada (613) 990-0752 (FAX: 952-6602) gcc/ 2010-10-11 John David Anglin * config/pa/linux-atomic.c (__sync_val_compare_and_swap_4): Return actual_oldval. Use __builtin_expect. (SUBWORD_VAL_CAS): Likewise. --- gcc-4.6.3/gcc/config/m68k/linux-atomic.c.~1~ 2012-06-18 22:48:07.000000000 +0200 +++ gcc-4.6.3/gcc/config/m68k/linux-atomic.c 2012-06-18 22:54:25.000000000 +0200 @@ -183,7 +183,7 @@ __sync_val_compare_and_swap_4 (int *ptr, fail = __kernel_cmpxchg (actual_oldval, newval, ptr); if (__builtin_expect (!fail, 1)) - return oldval; + return actual_oldval; } } @@ -213,7 +213,7 @@ __sync_val_compare_and_swap_4 (int *ptr, wordptr); \ \ if (__builtin_expect (!fail, 1)) \ - return oldval; \ + return (actual_oldval & mask) >> shift; \ } \ }