This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Suggested patch: remove __compare_and_swap



As Mark and David have noted on a couple of occasions, this function is
unused.  And it seems to trip port maintainers up on a pseudo-regular basis.
Why not get rid of it?

This patch passes build and test under x86/linux.  Overnight the powerpc-sim
cross will be checked as well.

It doesn't fix any particular bug, so it's not a particularly strong
candidate for the branch IMHO.

Phil


--- egcscurrent/libstdc++-v3/config/cpu/alpha/bits/atomicity.h	Tue Feb 27 19:14:15 2001
+++ egcschanging/libstdc++-v3/config/cpu/alpha/bits/atomicity.h	Tue Sep 18 19:15:25 2001
@@ -73,25 +73,4 @@ __atomic_add (volatile _Atomic_word* __m
       : "m" (*__mem), "r"(__val));
 }
 
-static inline int
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long *__p, long __oldval, long __newval)
-{
-  int __ret;
-
-  __asm__ __volatile__ (
-      "\n$Lcas_%=:\n\t"
-      "ldq_l  %0,%4\n\t"
-      "cmpeq  %0,%2,%0\n\t"
-      "beq    %0,3f\n\t"
-      "mov    %3,%0\n\t"
-      "stq_c  %0,%1\n\t"
-      "beq    %0,$Lcas_%=\n\t"
-      "mb"
-      : "=&r"(__ret), "=m"(*__p)
-      : "r"(__oldval), "r"(__newval), "m"(*__p));
-
-  return __ret;
-}
-
 #endif /* atomicity.h */
--- egcscurrent/libstdc++-v3/config/cpu/arm/bits/atomicity.h	Tue Feb 27 19:14:15 2001
+++ egcschanging/libstdc++-v3/config/cpu/arm/bits/atomicity.h	Tue Sep 18 19:15:41 2001
@@ -127,63 +127,6 @@ __atomic_add (volatile _Atomic_word *__m
 #endif
 }
 
-static inline int
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long *__p, long __oldval, long __newval)
-{
-  int __result;
-  long __tmp;
-#ifdef __thumb__
-  /* Since this function is inlined, we can't be sure of the alignment.  */
-  __asm__ __volatile__ (
-	"ldr     %0, 4f \n\t"
-	"bx      %0 \n\t"
-	".align 0 \n"
-	"4:\t"
-	".word   0f \n\t"
-	".code 32 \n"
-	"0:\t"
-	"ldr     %1, [%2] \n\t"
-        "mov     %0, #0 \n\t"
-        "cmp     %1, %4 \n\t"
-        "bne     1f \n\t"
-        "swp     %0, %3, [%2] \n\t"
-        "cmp     %1, %0 \n\t"
-        "swpne   %1, %0, [%2] \n\t"
-        "bne     0b \n\t"
-        "mov     %0, #1 \n"
-	"1:\t"
-	"ldr     %1, 2f \n\t"
-	"bx      %1 \n"
-	"2:\t"
-	".word   3f \n\t"
-	".code 16\n"
-	"3:\n"
-	: "=&l"(__result), "=&r"(__tmp) 
-	: "r" (__p), "r" (__newval), "r" (__oldval) 
-	: "cc", "memory");
-#else
-  __asm__ __volatile__ (
-	"\n"
-	"0:\t"
-	"ldr     %1, [%2] \n\t"
-	"mov     %0, #0 \n\t"
-	"cmp     %1, %4 \n\t"
-	"bne     1f \n\t"
-	"swp     %0, %3, [%2] \n\t"
-	"cmp     %1, %0 \n\t"
-	"swpne   %1, %0, [%2] \n\t"
-	"bne     0b \n\t"
-	"mov     %0, #1 \n"
-	"1:\n\t"
-	""
-	: "=&r"(__result), "=&r"(__tmp) 
-	: "r" (__p), "r" (__newval), "r" (__oldval) 
-	: "cc", "memory");
-#endif
-  return __result;
-}
-
 static inline long
 __attribute__ ((__unused__))
 __always_swap (volatile long *__p, long __newval)
--- egcscurrent/libstdc++-v3/config/cpu/generic/bits/atomicity.h	Tue Feb 27 19:14:15 2001
+++ egcschanging/libstdc++-v3/config/cpu/generic/bits/atomicity.h	Tue Sep 18 19:15:57 2001
@@ -48,15 +48,4 @@ __atomic_add (_Atomic_word* __mem, int _
   *__mem += __val;
 }
 
-static inline int
-__attribute__ ((__unused__))
-__compare_and_swap (long *__p, long __oldval, long __newval)
-{
-  if (*__p != __oldval)
-    return 0;
-
-  *__p = __newval;
-  return 1;
-}
-
 #endif /* atomicity.h */
--- egcscurrent/libstdc++-v3/config/cpu/i486/bits/atomicity.h	Tue Feb 27 19:14:15 2001
+++ egcschanging/libstdc++-v3/config/cpu/i486/bits/atomicity.h	Tue Sep 18 19:16:04 2001
@@ -52,19 +52,6 @@ __atomic_add (volatile _Atomic_word* __m
 			: : "ir" (__val), "m" (*__mem) : "memory");
 }
 
-static inline char
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long* __p, long __oldval, long __newval)
-{
-  char __ret;
-  long __readval;
-
-  __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
-                        : "=q" (__ret), "=m" (*__p), "=a" (__readval)
-                        : "r" (__newval), "m" (*__p), "a" (__oldval));
-  return __ret;
-}
-
 #endif /* atomicity.h */
 
 
--- egcscurrent/libstdc++-v3/config/cpu/ia64/bits/atomicity.h	Tue Feb 27 19:14:15 2001
+++ egcschanging/libstdc++-v3/config/cpu/ia64/bits/atomicity.h	Tue Sep 18 19:16:18 2001
@@ -48,11 +48,4 @@ __atomic_add (volatile _Atomic_word* __m
   __sync_fetch_and_add (__mem, __val);
 }
 
-static inline int
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long *__p, long __oldval, long __newval)
-{
-  return __sync_bool_compare_and_swap (__p, __oldval, __newval);
-}
-
 #endif /* atomicity.h */
--- egcscurrent/libstdc++-v3/config/cpu/mips/bits/atomicity.h	Mon Jul 30 21:49:30 2001
+++ egcschanging/libstdc++-v3/config/cpu/mips/bits/atomicity.h	Tue Sep 18 19:16:49 2001
@@ -75,31 +75,4 @@ __atomic_add (volatile _Atomic_word *__m
      : "memory");
 }
 
-static inline int
-__attribute__ ((unused))
-__compare_and_swap (volatile long int *__p, long int __oldval,
-		    long int __newval)
-{
-  long int __ret;
-
-  __asm__ __volatile__
-    ("/* Inline compare & swap */\n\t"
-     "1:\n\t"
-     "ll	%0,%4\n\t"
-     ".set	push\n"
-     ".set	noreorder\n\t"
-     "bne	%0,%2,2f\n\t"
-     "move	%0,%3\n\t"
-     ".set	pop\n\t"
-     "sc	%0,%1\n\t"
-     "beqz	%0,1b\n"
-     "2:\n\t"
-     "/* End compare & swap */"
-     : "=&r" (__ret), "=m" (*__p)
-     : "r" (__oldval), "r" (__newval), "m" (*__p)
-     : "memory");
-
-  return __ret;
-}
-
 #endif /* atomicity.h */
--- egcscurrent/libstdc++-v3/config/cpu/powerpc/bits/atomicity.h	Tue Feb 27 19:14:16 2001
+++ egcschanging/libstdc++-v3/config/cpu/powerpc/bits/atomicity.h	Tue Sep 18 19:16:27 2001
@@ -69,28 +69,6 @@ __atomic_add (volatile _Atomic_word *__m
 	: "cr0", "memory");
 }
 
-static inline int
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long *__p, long int __oldval, long int __newval)
-{
-  int __res;
-  __asm__ __volatile__ (
-	"/* Inline compare & swap */\n"
-	"0:\t"
-	"lwarx    %0,0,%1  \n\t"
-	"sub%I2c. %0,%0,%2 \n\t"
-	"cntlzw   %0,%0 \n\t"
-	"bne-     1f \n\t"
-	"stwcx.   %3,0,%1 \n\t"
-	"bne-     0b \n"
-	"1:\n\t"
-	"/* End compare & swap */"
-	: "=&b"(__res)
-	: "r"(__p), "Ir"(__oldval), "r"(__newval)
-	: "cr0", "memory");
-  return __res >> 5;
-}
-
 static inline long
 __attribute__ ((__unused__))
 __always_swap (volatile long *__p, long int __newval)
--- egcscurrent/libstdc++-v3/config/cpu/sparc/sparc32/bits/atomicity.h	Tue Feb 27 19:14:16 2001
+++ egcschanging/libstdc++-v3/config/cpu/sparc/sparc32/bits/atomicity.h	Tue Sep 18 19:16:32 2001
@@ -76,33 +76,4 @@ __atomic_add (volatile _Atomic_word* __m
 		       : "memory");
 }
 
-static int
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long *__p, long __oldval, long __newval)
-{
-  static unsigned char __lock;
-  long __ret, __tmp;
-
-  __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
-		       "	cmp	%0, 0\n\t"
-		       "	bne	1b\n\t"
-		       "	 nop"
-		       : "=&r" (__tmp)
-		       : "r" (&__lock)
-		       : "memory");
-  if (*__p != __oldval)
-    __ret = 0;
-  else
-    {
-      *__p = __newval;
-      __ret = 1;
-    }
-  __asm__ __volatile__("stb	%%g0, [%0]"
-		       : /* no outputs */
-		       : "r" (&__lock)
-		       : "memory");
-
-  return __ret;
-}
-
 #endif /* atomicity.h */
--- egcscurrent/libstdc++-v3/config/cpu/sparc/sparc64/bits/atomicity.h	Tue Feb 27 19:14:16 2001
+++ egcschanging/libstdc++-v3/config/cpu/sparc/sparc64/bits/atomicity.h	Tue Sep 18 19:16:41 2001
@@ -67,27 +67,4 @@ __atomic_add (volatile _Atomic_word* __m
 		       : "memory");
 }
 
-static inline int
-__attribute__ ((__unused__))
-__compare_and_swap (volatile long *__p, long __oldval, long __newval)
-{
-  register int __tmp;
-  register long __tmp2;
-
-  __asm__ __volatile__("1:	ldx	[%4], %0\n\t"
-		       "	mov	%2, %1\n\t"
-		       "	cmp	%0, %3\n\t"
-		       "	bne,a,pn %%xcc, 2f\n\t"
-		       "	 mov	0, %0\n\t"
-		       "	casx	[%4], %0, %1\n\t"
-		       "	sub	%0, %1, %0\n\t"
-		       "	brnz,pn	%0, 1b\n\t"
-		       "	 mov	1, %0\n\t"
-		       "2:"
-		       : "=&r" (__tmp), "=&r" (__tmp2)
-		       : "r" (__newval), "r" (__oldval), "r" (__p)
-		       : "memory");
-  return __tmp;
-}
-
 #endif /* atomicity.h */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]