Patchwork [ARM] Provide __builtin_expect() hints in linux-atomic.c

login
register
mail settings
Submitter Marcus Shawcroft
Date Sept. 1, 2010, 3:17 p.m.
Message ID <000401cb49e8$db9d98d0$92d8ca70$@shawcroft@arm.com>
Download mbox | patch
Permalink /patch/63383/
State New
Headers show

Comments

Marcus Shawcroft - Sept. 1, 2010, 3:17 p.m.
The out of line linux-atomic.c code does not provide __builtin_expect()
hints, this patch adds them..

Regression tested.

Ok?

/Marcus
2010-09-01  Marcus Shawcroft  <marcus.shawcroft@arm.com>

	* config/arm/linux-atomic.c (__sync_val_compare_and_swap_4): Insert __builtin_expect().
	(SUBWORD_VAL_CAS): Likewise.
Richard Earnshaw - Sept. 3, 2010, 9:41 a.m.
On Wed, 2010-09-01 at 16:17 +0100, Marcus Shawcroft wrote:
> The out of line linux-atomic.c code does not provide __builtin_expect()
> hints, this patch adds them..
> 
> Regression tested.
> 
> Ok?

OK.

R.

Patch

diff --git a/gcc/config/arm/linux-atomic.c b/gcc/config/arm/linux-atomic.c
index 685f16b..ddedeb5 100644
--- a/gcc/config/arm/linux-atomic.c
+++ b/gcc/config/arm/linux-atomic.c
@@ -155,12 +155,12 @@  __sync_val_compare_and_swap_4 (int *ptr, int oldval, int newval)
     {
       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)
+      if (__builtin_expect (!fail, 1))
         return oldval;
     }
 }
@@ -180,7 +180,8 @@  __sync_val_compare_and_swap_4 (int *ptr, int oldval, int newval)
       {									\
 	actual_oldval = *wordptr;					\
 									\
-	if (((actual_oldval & mask) >> shift) != (unsigned int) oldval)	\
+	if (__builtin_expect (((actual_oldval & mask) >> shift) !=      \
+                              (unsigned int) oldval, 0))                \
           return (actual_oldval & mask) >> shift;			\
 									\
 	actual_newval = (actual_oldval & ~mask)				\
@@ -189,7 +190,7 @@  __sync_val_compare_and_swap_4 (int *ptr, int oldval, int newval)
 	fail = __kernel_cmpxchg (actual_oldval, actual_newval,		\
 				 wordptr);				\
 									\
-	if (!fail)							\
+      if (__builtin_expect (!fail, 1))                                  \
           return oldval;						\
       }									\
   }