about summary refs log tree commit diff
path: root/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/sparc/sparc32/sparcv9/bits/atomic.h')
-rw-r--r--sysdeps/sparc/sparc32/sparcv9/bits/atomic.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h b/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
index b1a89584f6..937d7a149f 100644
--- a/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
+++ b/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
@@ -55,10 +55,16 @@ 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; })
 
 /* This can be implemented if needed.  */