public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Kaz Kojima <kkojima@rr.iij4u.or.jp>
To: libc-hacker@sources.redhat.com
Subject: [PATCH] SH: nptl fixups
Date: Mon, 21 Jan 2008 14:27:00 -0000	[thread overview]
Message-ID: <20080121.232728.71092559.kkojima@rr.iij4u.or.jp> (raw)

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

             reply	other threads:[~2008-01-21 14:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-21 14:27 Kaz Kojima [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-09-12 22:28 Kaz Kojima
2006-09-17  6:02 ` Ulrich Drepper
2004-06-13  6:16 Kaz Kojima
2004-06-17 23:58 ` Ulrich Drepper
2004-06-01  5:33 Kaz Kojima
2004-06-01 18:17 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080121.232728.71092559.kkojima@rr.iij4u.or.jp \
    --to=kkojima@rr.iij4u.or.jp \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).