about summary refs log tree commit diff
path: root/sysdeps/sparc/sparc64
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/sparc/sparc64')
-rw-r--r--sysdeps/sparc/sparc64/bits/atomic.h28
1 files changed, 20 insertions, 8 deletions
diff --git a/sysdeps/sparc/sparc64/bits/atomic.h b/sysdeps/sparc/sparc64/bits/atomic.h
index 0afbb4ba5e..96611de42f 100644
--- a/sysdeps/sparc/sparc64/bits/atomic.h
+++ b/sysdeps/sparc/sparc64/bits/atomic.h
@@ -55,20 +55,32 @@ typedef uintmax_t uatomic_max_t;
 ({									      \
   __typeof (*(mem)) __acev_tmp;						      \
   __typeof (mem) __acev_mem = (mem);					      \
-  __asm __volatile ("cas [%4], %2, %0"					      \
-		    : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
-		    : "r" (oldval), "m" (*__acev_mem), "r" (__acev_mem),      \
-		      "0" (newval) : "memory");				      \
+  if (__builtin_constant_p (oldval) && (oldval) == 0)			      \
+    __asm __volatile ("cas [%3], %%g0, %0"				      \
+		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
+		      : "m" (*__acev_mem), "r" (__acev_mem),		      \
+		        "0" (newval) : "memory");			      \
+  else									      \
+    __asm __volatile ("cas [%4], %2, %0"				      \
+		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
+		      : "r" (oldval), "m" (*__acev_mem), "r" (__acev_mem),    \
+		        "0" (newval) : "memory");			      \
   __acev_tmp; })
 
 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
 ({									      \
   __typeof (*(mem)) __acev_tmp;						      \
   __typeof (mem) __acev_mem = (mem);					      \
-  __asm __volatile ("casx [%4], %2, %0"					      \
-		    : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
-		    : "r" ((long) (oldval)), "m" (*__acev_mem),		      \
-		      "r" (__acev_mem), "0" ((long) (newval)) : "memory");    \
+  if (__builtin_constant_p (oldval) && (oldval) == 0)			      \
+    __asm __volatile ("casx [%3], %%g0, %0"				      \
+		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
+		      : "m" (*__acev_mem), "r" (__acev_mem),		      \
+		        "0" ((long) (newval)) : "memory");		      \
+  else									      \
+    __asm __volatile ("casx [%4], %2, %0"				      \
+		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
+		      : "r" ((long) (oldval)), "m" (*__acev_mem),	      \
+		        "r" (__acev_mem), "0" ((long) (newval)) : "memory");  \
   __acev_tmp; })
 
 #define atomic_exchange_acq(mem, newvalue) \