[PATCH 6/8] i386: bitops: Don't mark memory as clobbered unnecessarily

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Satyam Sharma
Date: Monday, July 23, 2007 - 9:05 am

From: Satyam Sharma <ssatyam@cse.iitk.ac.in>

[6/8] i386: bitops: Don't mark memory as clobbered unnecessarily

The goal is to let gcc generate good, beautiful, optimized code.

But test_and_set_bit, test_and_clear_bit, __test_and_change_bit,
and test_and_change_bit unnecessarily mark all of memory as clobbered,
thereby preventing gcc from doing perfectly valid optimizations.

The case of __test_and_change_bit() is particularly surprising, given
that it's a variant where we don't make any guarantees at all.

Even for the other three cases, the (only) instruction that accesses
shared memory is btsl/btrl/btcl and requires locking and atomicity.
But we handle that properly already by the use of the lock prefix.
Also, "=m" is already specified in the output operands of the asm
for the passed bit-string pointer, so the gcc optimizer knows what
to do and what not to do anyway.

So there's no point clobbering all of memory in these functions.

Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
Cc: David Howells <dhowells@redhat.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>

---

 include/asm-i386/bitops.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/asm-i386/bitops.h b/include/asm-i386/bitops.h
index 0f5634b..f37b8a2 100644
--- a/include/asm-i386/bitops.h
+++ b/include/asm-i386/bitops.h
@@ -164,7 +164,7 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %2,%1\n\tsbbl %0,%0"
 		:"=r" (oldbit),"=m" (*addr)
-		:"r" (nr) : "memory");
+		:"r" (nr));
 	return oldbit;
 }
 
@@ -208,7 +208,7 @@ static inline int test_and_clear_bit(int nr, unsigned long *addr)
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %2,%1\n\tsbbl %0,%0"
 		:"=r" (oldbit),"=m" (*addr)
-		:"r" (nr) : "memory");
+		:"r" (nr));
 	return oldbit;
 }
 
@@ -254,7 +254,7 @@ static inline int __test_and_change_bit(int nr, unsigned long *addr)
 	__asm__ __volatile__(
 		"btcl %2,%1\n\tsbbl %0,%0"
 		:"=r" (oldbit),"=m" (*addr)
-		:"r" (nr) : "memory");
+		:"r" (nr));
 	return oldbit;
 }
 
@@ -275,7 +275,7 @@ static inline int test_and_change_bit(int nr, unsigned long *addr)
 	__asm__ __volatile__( LOCK_PREFIX
 		"btcl %2,%1\n\tsbbl %0,%0"
 		:"=r" (oldbit),"=m" (*addr)
-		:"r" (nr) : "memory");
+		:"r" (nr));
 	return oldbit;
 }
 
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/8] i386: bitops: Cleanup, sanitize, optimize, Satyam Sharma, (Mon Jul 23, 9:05 am)
[PATCH 1/8] i386: bitops: Update/correct comments, Satyam Sharma, (Mon Jul 23, 9:05 am)
[PATCH 6/8] i386: bitops: Don't mark memory as clobbered u ..., Satyam Sharma, (Mon Jul 23, 9:05 am)
Re: [PATCH 7/8] i386: bitops: Kill needless usage of __asm ..., Jeremy Fitzhardinge, (Mon Jul 23, 9:23 am)
Re: [PATCH 7/8] i386: bitops: Kill needless usage of __asm ..., Jeremy Fitzhardinge, (Mon Jul 23, 10:39 am)
Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobber ..., Jeremy Fitzhardinge, (Mon Jul 23, 10:49 am)
Re: [PATCH 7/8] i386: bitops: Kill needless usage of __asm ..., Jeremy Fitzhardinge, (Mon Jul 23, 11:28 am)
Re: [PATCH 7/8] i386: bitops: Kill needless usage of __asm ..., Jeremy Fitzhardinge, (Mon Jul 23, 1:40 pm)
Re: [PATCH 8/8] i386: bitops: smp_mb__{before, after}_clea ..., Jeremy Fitzhardinge, (Tue Jul 24, 12:48 am)
Re: [PATCH 4/8] i386: bitops: Kill volatile-casting of mem ..., Benjamin Herrenschmidt, (Tue Jul 24, 2:49 am)
Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobber ..., Benjamin Herrenschmidt, (Tue Jul 24, 2:52 am)
Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobber ..., Jeremy Fitzhardinge, (Tue Jul 24, 2:31 pm)
Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobber ..., Benjamin Herrenschmidt, (Tue Jul 24, 2:36 pm)
Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobber ..., Benjamin Herrenschmidt, (Tue Jul 24, 2:37 pm)
Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobber ..., Benjamin Herrenschmidt, (Tue Jul 24, 3:32 pm)
Re: [PATCH 0/8] i386: bitops: Cleanup, sanitize, optimize, Denis Vlasenko, (Mon Jul 30, 10:57 am)
Re: [PATCH 0/8] i386: bitops: Cleanup, sanitize, optimize, Satyam Sharma, (Mon Jul 30, 6:07 pm)