Subject: port-sh3/20311: lock.h simple lock fix / optimization
To: None <gnats-bugs@gnats.netbsd.org>
From: None <itohy@netbsd.org>
List: netbsd-bugs
Date: 02/12/2003 22:45:03
>Number:         20311
>Category:       port-sh3
>Synopsis:       lock.h simple lock fix / optimization
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sh3-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 12 05:46:02 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     ITOH Yasufumi
>Release:        NetBSD 1.6N
>Organization:
>Environment:
System: NetBSD illusion.my.domain 1.6N NetBSD 1.6N (ILLUSION.test) #488: Tue Feb 11 10:03:41 JST 2003 itohy@pino.my.domain:/w/src/sys/arch/dreamcast/compile/ILLUSION.test dreamcast
Architecture: sh3el
Machine: dreamcast

>Description:
	__cpu_simple_lock_t is defined int, which is wrong (the locked value
	doesn't match to __SIMPLELOCK_LOCKED) on big-endian platforms.
	"tas" instruction is byte size, and the type should be a byte type.

	Optimization to __cpu_simple_lock_try().

>How-To-Repeat:
	Code inspection.

>Fix:
	Here's the proposed change.

Index: lock.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sh3/include/lock.h,v
retrieving revision 1.4
diff -u -r1.4 lock.h
--- lock.h	2002/09/16 09:12:50	1.4
+++ lock.h	2003/02/12 13:29:14
@@ -43,7 +43,7 @@
 #ifndef _SH3_LOCK_H_
 #define	_SH3_LOCK_H_
 
-typedef	__volatile int		__cpu_simple_lock_t;
+typedef	__volatile unsigned char __cpu_simple_lock_t;
 
 #define	__SIMPLELOCK_LOCKED	0x80
 #define	__SIMPLELOCK_UNLOCKED	0
@@ -80,14 +80,10 @@
 	int __rv;
 
 	__asm __volatile(
-		"	mov	#1, r1	\n"
-		"	mov.l	r1, %1	\n"
 		"	tas.b	%0	\n"
-		"	bt	1f	\n"
-		"	mov	#0, r1	\n"
-		"	mov.l	r1, %1	\n"
-		"1:			\n"
-		: "=m" (*alp), "=m" (__rv) :: "r1");
+		"	mov	#0, %1	\n"
+		"	rotcl	%1	\n"
+		: "=m" (*alp), "=r" (__rv));
 
 	return (__rv);
 }
>Release-Note:
>Audit-Trail:
>Unformatted: