Re: [PATCH] x86: simplify sync_test_bit()

Previous thread: [PATCH] x86_64: do not reserve ramdisk two times by Yinghai Lu on Thursday, March 13, 2008 - 11:01 pm. (1 message)

Next thread: linux-next20080314 build fails with !CONFIG_PM by Kamalesh Babulal on Friday, March 14, 2008 - 12:57 am. (7 messages)
From: Jan Beulich
Date: Friday, March 14, 2008 - 12:56 am

There really is no need for a redundant implementation here, just keep
the alternative name for allowing consumers to use consistent naming.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

--- a/include/asm-x86/sync_bitops.h
+++ b/include/asm-x86/sync_bitops.h
@@ -130,26 +130,7 @@ static inline int sync_test_and_change_b
 	return oldbit;
 }
 
-static __always_inline int sync_constant_test_bit(int nr, const volatile unsigned long *addr)
-{
-	return ((1UL << (nr & 31)) &
-		(((const volatile unsigned int *)addr)[nr >> 5])) != 0;
-}
-
-static inline int sync_var_test_bit(int nr, const volatile unsigned long * addr)
-{
-	int oldbit;
-
-	__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
-			     :"=r" (oldbit)
-			     :"m" (ADDR),"Ir" (nr));
-	return oldbit;
-}
-
-#define sync_test_bit(nr,addr)			\
-	(__builtin_constant_p(nr) ?		\
-	 sync_constant_test_bit((nr),(addr)) :	\
-	 sync_var_test_bit((nr),(addr)))
+#define sync_test_bit test_bit
 
 #undef ADDR
 



--

From: Jeremy Fitzhardinge
Date: Friday, March 14, 2008 - 8:03 am

Hm,

#define sync_test_bit(nr, addr) test_bit(nr, addr)

would be better, but seems reasonable to me. Or even an inline for 
consistency.

J
--

From: Jan Beulich
Date: Friday, March 14, 2008 - 8:20 am

I'm usually intentionally using just the names, without parameters and
not as inline, in such alias definitions so that in case the name gets used
as a function pointer (arguably unlikely here) there's not going to be
any missing definition or duplicate function instantiation. But from a
functionality point of view, either of the alternatives you suggest is
of course as good.

Jan

--

From: Jeremy Fitzhardinge
Date: Friday, March 14, 2008 - 8:43 am

I'm especially wary of the naked #define, since it will affect any 
instance of sync_test_bit:

struct bit_thingy {
	unsigned sync_test_bit:1;
	unsigned other_test_bit:1;
	...
};

J
--

From: Ingo Molnar
Date: Friday, March 21, 2008 - 4:18 am

thanks, applied.

	Ingo
--

From: Jeremy Fitzhardinge
Date: Saturday, March 22, 2008 - 1:27 pm

Please use this instead.

    J

Subject: x86: use macro parameters on sync_test_bit

Using a naked parameterless macro could lead to other tokens being
unexpectedly replaced.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 include/asm-x86/sync_bitops.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

===================================================================
--- a/include/asm-x86/sync_bitops.h
+++ b/include/asm-x86/sync_bitops.h
@@ -123,7 +123,7 @@
 	return oldbit;
 }
 
-#define sync_test_bit test_bit
+#define sync_test_bit(nr, addr) test_bit(nr, addr)
 
 #undef ADDR
 


--

From: Ingo Molnar
Date: Wednesday, March 26, 2008 - 12:27 am

thanks Jeremy, applied.

	Ingo
--