[kaffe] CVS kaffe (dalibor): Fixed sparc compare_and_swap to use glibc implementation

Kaffe CVS cvs-commits at kaffe.org
Fri Mar 12 03:48:02 PST 2004


PatchSet 4511 
Date: 2004/03/12 11:45:17
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Fixed sparc compare_and_swap to use glibc implementation

2004-03-12  Dalibor Topic <robilad at kaffe.org>

        * config/sparc/atomicity-sparc32.h,
        config/sparc/atomicity-sparc32v9.h,
        config/sparc/atomicity-sparc64.h:
        New files, taken from glib 2.3.2.

        * THIRDPARTY: Updated.

        * config/Makefile.am
        (EXTRA_DIST) Added new files.

        * config/Makefile.in
        Regenerated.

        * config/sparc/common.h
        (COMPARE_AND_EXCHANGE) Call compare_and_swap inline function
        from atomicity-<platform>.h.

        Reported by: Riccardo Mottola <zuse at libero.it>

Members: 
	ChangeLog:1.2090->1.2091 
	THIRDPARTY:1.9->1.10 
	config/Makefile.am:1.37->1.38 
	config/Makefile.in:1.117->1.118 
	config/sparc/atomicity-sparc32.h:INITIAL->1.1 
	config/sparc/atomicity-sparc32v9.h:INITIAL->1.1 
	config/sparc/atomicity-sparc64.h:INITIAL->1.1 
	config/sparc/common.h:1.8->1.9 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2090 kaffe/ChangeLog:1.2091
--- kaffe/ChangeLog:1.2090	Fri Mar 12 10:38:42 2004
+++ kaffe/ChangeLog	Fri Mar 12 11:45:17 2004
@@ -1,3 +1,24 @@
+2004-03-12  Dalibor Topic <robilad at kaffe.org>
+
+	* config/sparc/atomicity-sparc32.h,
+	config/sparc/atomicity-sparc32v9.h,
+	config/sparc/atomicity-sparc64.h:
+	New files, taken from glib 2.3.2.
+
+	* THIRDPARTY: Updated.
+
+	* config/Makefile.am
+	(EXTRA_DIST) Added new files.
+
+	* config/Makefile.in
+	Regenerated.
+
+	* config/sparc/common.h
+	(COMPARE_AND_EXCHANGE) Call compare_and_swap inline function
+        from atomicity-<platform>.h.
+
+	Reported by: Riccardo Mottola <zuse at libero.it>
+
 2004-03-12  Riccardo Mottola <zuse at libero.it>
 
 	* config/m68k/jit-m68k.def:
Index: kaffe/THIRDPARTY
diff -u kaffe/THIRDPARTY:1.9 kaffe/THIRDPARTY:1.10
--- kaffe/THIRDPARTY:1.9	Thu Mar 11 16:22:51 2004
+++ kaffe/THIRDPARTY	Fri Mar 12 11:45:19 2004
@@ -167,7 +167,7 @@
 
 At the time of writing, Kaffe uses getaddrinfo 1.6.1.
 
-* M68k and ARM atomic compare_and_swap
+* M68k, SPARC and ARM atomic compare_and_swap
 
 Taken from GNU libc 2.3.2, which is licensed under the GNU Lesser General 
 Public License. See file license-lesser.terms for details.
Index: kaffe/config/Makefile.am
diff -u kaffe/config/Makefile.am:1.37 kaffe/config/Makefile.am:1.38
--- kaffe/config/Makefile.am:1.37	Mon Jan 12 09:06:56 2004
+++ kaffe/config/Makefile.am	Fri Mar 12 11:45:20 2004
@@ -72,6 +72,7 @@
 	alpha/sysdepCallMethod.h \
 	alpha/threads.h \
 	alpha/trampolines.c \
+	arm/atomicity.h \
 	arm/callKaffeException.h \
 	arm/common.h \
 	arm/jit-arm.def \
@@ -294,6 +295,9 @@
 	s390/linux/md.h \
 	s390/sysdepCallMethod.h \
 	s390/threads.h \
+	sparc/atomicity-sparc32.h \
+	sparc/atomicity-sparc32v9.h \
+	sparc/atomicity-sparc64.h \
 	sparc/bsdi3/config.frag \
 	sparc/bsdi3/jit-md.h \
 	sparc/bsdi3/md.c \
Index: kaffe/config/Makefile.in
diff -u kaffe/config/Makefile.in:1.117 kaffe/config/Makefile.in:1.118
--- kaffe/config/Makefile.in:1.117	Mon Mar  8 21:21:00 2004
+++ kaffe/config/Makefile.in	Fri Mar 12 11:45:20 2004
@@ -357,6 +357,7 @@
 	alpha/sysdepCallMethod.h \
 	alpha/threads.h \
 	alpha/trampolines.c \
+	arm/atomicity.h \
 	arm/callKaffeException.h \
 	arm/common.h \
 	arm/jit-arm.def \
@@ -579,6 +580,9 @@
 	s390/linux/md.h \
 	s390/sysdepCallMethod.h \
 	s390/threads.h \
+	sparc/atomicity-sparc32.h \
+	sparc/atomicity-sparc32v9.h \
+	sparc/atomicity-sparc64.h \
 	sparc/bsdi3/config.frag \
 	sparc/bsdi3/jit-md.h \
 	sparc/bsdi3/md.c \
===================================================================
Checking out kaffe/config/sparc/atomicity-sparc32.h
RCS:  /home/cvs/kaffe/kaffe/config/sparc/atomicity-sparc32.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/config/sparc/atomicity-sparc32.h	Fri Mar 12 11:47:53 2004
@@ -0,0 +1,52 @@
+/* Low-level functions for atomic operations.  Sparc32 version.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _ATOMICITY_H
+#define _ATOMICITY_H	1
+
+static int
+__attribute__ ((unused))
+compare_and_swap (volatile long int *p, long int oldval, long int newval)
+{
+  static unsigned char lock;
+  int 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 */
===================================================================
Checking out kaffe/config/sparc/atomicity-sparc32v9.h
RCS:  /home/cvs/kaffe/kaffe/config/sparc/atomicity-sparc32v9.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/config/sparc/atomicity-sparc32v9.h	Fri Mar 12 11:47:54 2004
@@ -0,0 +1,45 @@
+/* Low-level functions for atomic operations.  Sparc32+v9 version.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _ATOMICITY_H
+#define _ATOMICITY_H	1
+
+static inline int
+__attribute__ ((unused))
+compare_and_swap (volatile long int *p, long int oldval, long int newval)
+{
+  register long int tmp, tmp2;
+
+  __asm__ __volatile__("1:	lduw	[%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"
+		       "	cas	[%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 */
===================================================================
Checking out kaffe/config/sparc/atomicity-sparc64.h
RCS:  /home/cvs/kaffe/kaffe/config/sparc/atomicity-sparc64.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/config/sparc/atomicity-sparc64.h	Fri Mar 12 11:47:54 2004
@@ -0,0 +1,47 @@
+/* Low-level functions for atomic operations.  Sparc64 version.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _ATOMICITY_H
+#define _ATOMICITY_H	1
+
+#include <inttypes.h>
+
+static inline int
+__attribute__ ((unused))
+compare_and_swap (volatile long int *p, long int oldval, long int newval)
+{
+  register long int tmp, 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: kaffe/config/sparc/common.h
diff -u kaffe/config/sparc/common.h:1.8 kaffe/config/sparc/common.h:1.9
--- kaffe/config/sparc/common.h:1.8	Mon Jun 18 10:40:39 2001
+++ kaffe/config/sparc/common.h	Fri Mar 12 11:45:20 2004
@@ -14,6 +14,17 @@
 #ifndef __sparc_common_h
 #define __sparc_common_h
 
+/* Include the right compare_and_swap definition */
+#if defined(__sparcv9)
+#include "atomicity-sparc32v9.h"
+#else /* !defined(__sparcv9) */
+#if defined(__arch64__)
+#include "atomicity-sparc64.h"
+#else /* !defined(__arch64__) */
+#include "atomicity-sparc32.h"
+#endif /* defined(__arch64__) */
+#endif /* defined(__sparcv9) */
+
 #if NEED_sysdepCallMethod
 
 #define LONG_SYSDEP 1
@@ -23,35 +34,12 @@
 
 #endif /* NEED_sysdepCallMethod */
 
-
-/*
- * Do an atomic exchange.  The contents of address 'A' is exchanged
- * with value 'N'.
- */
-#define ATOMIC_EXCHANGE(A,N) \
-	asm volatile("swap [%2],%0" : "=&r" (N) : "0" (N), "r" (A) : "cc", "memory" );
-
-#if 0
-#undef ATOMIC_EXCHANGE
-#warning "jthread COMPARE_AND_EXCHANGE"
-
 /*
  * Do an atomic compare and exchange.  The address 'A' is checked against
  * value 'O' and if they match it's exchanged with value 'N'.
- * We return '1' if the exchange is sucessful, otherwise 0.
+ * We return '1' if the exchange is successful, otherwise 0.
  */
-#define COMPARE_AND_EXCHANGE(A,O,N)		\
-({						\
-    int ret = 0;				\
-    jthread_suspendall();			\
-						\
-    if (*(A) == (O)) {				\
-	*(A) = (N);				\
-	ret = 1;				\
-    }						\
-    jthread_unsuspendall();			\
-    ret;					\
-})
-#endif
+
+#define COMPARE_AND_EXCHANGE(A, O, N)  (compare_and_swap((long int*) A, (long int) O, (long int) N))
 
 #endif




More information about the kaffe mailing list