This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] SH: nptl fixups


Hi,

The appended patch fixes several tinko&typo on SH port.
The currnet implementation of XADD clobbers the register
value in the critical section and doesn't match the correct
xadd behavior when this section restarts.  The patch
introduces a tempolary register to avoid it.
The other hunks of the patch are to fix the rather obvious
typo and oversight when I interpreted x86 pthread_rwlock_timed*
sources.
Uli, could you please approve this patch?

Regards,
        kaz
--
2008-01-21  Kaz Kojima  <kkojima@rr.iij4u.or.jp>

	* sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h (XADD): Use
	a scratch register.
	* sysdeps/unix/sysv/linux/sh/lowlevellock.S
	(__lll_lock_wait_private): Fix typo.
	* sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S
	(pthread_barrier_wait): Likewise.  Adjust XADD use.
	* sysdeps/unix/sysv/linux/sh/sem_post.S (__new_sem_post):
	Adjust XADD use.
	* sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S
	(pthread_rwlock_timedrdlock): Return correct return value.
	* sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S
	(pthread_rwlock_timedwrlock): Likewise.

diff -uprN ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h
--- ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h	2004-03-20 15:13:03.000000000 +0900
+++ LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h	2008-01-18 16:31:16.000000000 +0900
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2008 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
@@ -44,14 +44,16 @@
 	mov.l	reg, mem; \
 99:	mov	r1, r15
 
-#define	XADD(reg, mem, old) \
+#define	XADD(reg, mem, old, tmp) \
 	.align	2; \
 	mova	99f, r0; \
+	nop; \
 	mov	r15, r1; \
-	mov	_IMM6, r15; \
+	mov	_IMM8, r15; \
 98:	mov.l	mem, old; \
-	add	old, reg; \
-	mov.l	reg, mem; \
+	mov	reg, tmp; \
+	add	old, tmp; \
+	mov.l	tmp, mem; \
 99:	mov	r1, r15
 
 #define	XCHG(reg, mem, old) \
diff -uprN ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S
--- ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S	2007-12-06 09:37:23.000000000 +0900
+++ LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S	2008-01-18 16:32:03.000000000 +0900
@@ -1,4 +1,5 @@
-/* Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2005, 2007, 2008
+   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
@@ -143,7 +144,7 @@ __lll_lock_wait_private:
 	bf	1b
 
 	mov.l	@r15+, r8
-	ret
+	rts
 	 mov	r2, r0
 	cfi_endproc
 	.size	__lll_lock_wait_private,.-__lll_lock_wait_private
diff -uprN ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S
--- ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S	2007-08-04 09:57:13.000000000 +0900
+++ LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S	2008-01-18 16:31:25.000000000 +0900
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2007, 2008 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
@@ -86,7 +86,7 @@ pthread_barrier_wait:
 	   initial count unlock the object.  */
 	mov	#1, r3
 	mov.l	@(INIT_COUNT,r8), r4
-	XADD	(r3, @(LEFT,r8), r2)
+	XADD	(r3, @(LEFT,r8), r2, r5)
 	add	#-1, r4
 	cmp/eq	r2, r4
 	bf	10f
@@ -131,7 +131,7 @@ pthread_barrier_wait:
 	   initial count unlock the object.  */
 	mov	#1, r3
 	mov.l	@(INIT_COUNT,r8), r4
-	XADD	(r3, @(LEFT,r8), r2)
+	XADD	(r3, @(LEFT,r8), r2, r5)
 	add	#-1, r4
 	cmp/eq	r2, r4
 	bf	5f
@@ -144,7 +144,7 @@ pthread_barrier_wait:
 	mov	#-1, r0		/* == PTHREAD_BARRIER_SERIAL_THREAD */
 	lds.l	@r15+, pr
 	mov.l	@r15+, r8
-	ret
+	rts
 	 mov.l	@r15+, r9
 
 1:
diff -uprN ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S
--- ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S	2007-08-16 08:16:43.000000000 +0900
+++ LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S	2008-01-18 16:33:16.000000000 +0900
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2007, 2008 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
@@ -232,6 +232,7 @@ pthread_rwlock_timedrdlock:
 	.word	TID - TLS_PRE_TCB_SIZE
 
 6:
+	mov	r3, r10
 	mov	r8, r4
 #if MUTEX != 0
 	add	#MUTEX, r4
@@ -244,7 +245,7 @@ pthread_rwlock_timedrdlock:
 	 nop
 .Lwake2b:
 	bra	7b
-	 mov	#0, r3
+	 mov	r10, r3
 
 8:
 	/* Overflow.  */
@@ -278,6 +279,7 @@ pthread_rwlock_timedrdlock:
 	 nop
 
 12:
+	mov	r3, r10
 	mov	r8, r5
 #if MUTEX != 0
 	add	#MUTEX, r5
@@ -290,7 +292,7 @@ pthread_rwlock_timedrdlock:
 	 mov	r2, r4
 .Lwait3b:
 	bra	13b
-	 nop
+	 mov	r10, r3
 
 16:
 	bra	17b
diff -uprN ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S
--- ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S	2007-08-16 08:16:43.000000000 +0900
+++ LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S	2008-01-18 16:33:30.000000000 +0900
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2007, 2008 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
@@ -225,6 +225,7 @@ pthread_rwlock_timedwrlock:
 	bra	9b
 	 mov	#EDEADLK, r3
 6:
+	mov	r3, r10
 	mov	r8, r4
 #if MUTEX != 0
 	add	#MUTEX, r4
@@ -237,7 +238,7 @@ pthread_rwlock_timedwrlock:
 	 nop
 .Lwake6b:
 	bra	7b
-	 mov	#0, r3
+	 mov	r10, r3
 
 .Ltidoff:
 	.word	TID - TLS_PRE_TCB_SIZE
@@ -266,6 +267,7 @@ pthread_rwlock_timedwrlock:
 	 nop
 
 12:
+	mov	r3, r10
 	mov	r8, r5
 #if MUTEX != 0
 	add	#MUTEX, r5
@@ -278,7 +280,7 @@ pthread_rwlock_timedwrlock:
 	 mov	r2, r4
 .Lwait7b:
 	bra	13b
-	 nop
+	 mov	r10, r3
 
 16:
 	bra	17b
diff -uprN ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S
--- ORIG/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S	2007-08-04 09:57:14.000000000 +0900
+++ LOCAL/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S	2008-01-18 16:31:16.000000000 +0900
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2007, 2008 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
@@ -31,7 +31,7 @@
 	.align	5
 __new_sem_post:
 	mov	#1, r3
-	XADD (r3, @(VALUE,r4), r2)
+	XADD (r3, @(VALUE,r4), r2, r5)
 	mov.l	@(NWAITERS,r4), r2
 	tst	r2, r2
 	bt	2f


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