aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86/bitops.h
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-06-20 01:28:24 -0400
committerIngo Molnar <mingo@elte.hu>2008-06-20 02:08:49 -0400
commit7dbceaf9bb68919651901b101f44edd5391ee489 (patch)
tree1d9686536675d4d2307ffe2380af55ff023365b7 /include/asm-x86/bitops.h
parent1a750e0cd7a30c478723ecfa1df685efcdd38a90 (diff)
x86, bitops: make constant-bit set/clear_bit ops faster, adapt, clean up
fix integration bug introduced by "x86: bitops take an unsigned long *" which turned "(void *) + x" into "(long *) + x". small cleanups to make it more apparent which value get propagated where. Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/asm-x86/bitops.h')
-rw-r--r--include/asm-x86/bitops.h36
1 files changed, 22 insertions, 14 deletions
diff --git a/include/asm-x86/bitops.h b/include/asm-x86/bitops.h
index ab7635a4acd9..6c5054819719 100644
--- a/include/asm-x86/bitops.h
+++ b/include/asm-x86/bitops.h
@@ -28,16 +28,15 @@
28#define BITOP_ADDR(x) "+m" (*(volatile long *) (x)) 28#define BITOP_ADDR(x) "+m" (*(volatile long *) (x))
29#endif 29#endif
30 30
31#define ADDR BITOP_ADDR(addr) 31#define ADDR BITOP_ADDR(addr)
32 32
33/* 33/*
34 * We do the locked ops that don't return the old value as 34 * We do the locked ops that don't return the old value as
35 * a mask operation on a byte. 35 * a mask operation on a byte.
36 */ 36 */
37#define IS_IMMEDIATE(nr) \ 37#define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
38 (__builtin_constant_p(nr)) 38#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
39#define CONST_MASK_ADDR BITOP_ADDR(addr + (nr>>3)) 39#define CONST_MASK(nr) (1 << ((nr) & 7))
40#define CONST_MASK (1 << (nr & 7))
41 40
42/** 41/**
43 * set_bit - Atomically set a bit in memory 42 * set_bit - Atomically set a bit in memory
@@ -56,13 +55,17 @@
56 */ 55 */
57static inline void set_bit(unsigned int nr, volatile unsigned long *addr) 56static inline void set_bit(unsigned int nr, volatile unsigned long *addr)
58{ 57{
59 if (IS_IMMEDIATE(nr)) 58 if (IS_IMMEDIATE(nr)) {
60 asm volatile(LOCK_PREFIX "orb %1,%0" : CONST_MASK_ADDR : "i" (CONST_MASK) : "memory"); 59 asm volatile(LOCK_PREFIX "orb %1,%0"
61 else 60 : CONST_MASK_ADDR(nr, addr)
62 asm volatile(LOCK_PREFIX "bts %1,%0" : ADDR : "Ir" (nr) : "memory"); 61 : "i" (CONST_MASK(nr))
62 : "memory");
63 } else {
64 asm volatile(LOCK_PREFIX "bts %1,%0"
65 : BITOP_ADDR(addr) : "Ir" (nr) : "memory");
66 }
63} 67}
64 68
65
66/** 69/**
67 * __set_bit - Set a bit in memory 70 * __set_bit - Set a bit in memory
68 * @nr: the bit to set 71 * @nr: the bit to set
@@ -89,10 +92,15 @@ static inline void __set_bit(int nr, volatile unsigned long *addr)
89 */ 92 */
90static inline void clear_bit(int nr, volatile unsigned long *addr) 93static inline void clear_bit(int nr, volatile unsigned long *addr)
91{ 94{
92 if (IS_IMMEDIATE(nr)) 95 if (IS_IMMEDIATE(nr)) {
93 asm volatile(LOCK_PREFIX "andb %1,%0" : CONST_MASK_ADDR : "i" (~CONST_MASK)); 96 asm volatile(LOCK_PREFIX "andb %1,%0"
94 else 97 : CONST_MASK_ADDR(nr, addr)
95 asm volatile(LOCK_PREFIX "btr %1,%0" : ADDR : "Ir" (nr)); 98 : "i" (~CONST_MASK(nr)));
99 } else {
100 asm volatile(LOCK_PREFIX "btr %1,%0"
101 : BITOP_ADDR(addr)
102 : "Ir" (nr));
103 }
96} 104}
97 105
98/* 106/*