Commit 7dbceaf9 authored by Ingo Molnar's avatar Ingo Molnar

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: default avatarIngo Molnar <mingo@elte.hu>
parent 1a750e0c
...@@ -34,10 +34,9 @@ ...@@ -34,10 +34,9 @@
* We do the locked ops that don't return the old value as * We do the locked ops that don't return the old value as
* a mask operation on a byte. * a mask operation on a byte.
*/ */
#define IS_IMMEDIATE(nr) \ #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
(__builtin_constant_p(nr)) #define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
#define CONST_MASK_ADDR BITOP_ADDR(addr + (nr>>3)) #define CONST_MASK(nr) (1 << ((nr) & 7))
#define CONST_MASK (1 << (nr & 7))
/** /**
* set_bit - Atomically set a bit in memory * set_bit - Atomically set a bit in memory
...@@ -56,13 +55,17 @@ ...@@ -56,13 +55,17 @@
*/ */
static inline void set_bit(unsigned int nr, volatile unsigned long *addr) static inline void set_bit(unsigned int nr, volatile unsigned long *addr)
{ {
if (IS_IMMEDIATE(nr)) if (IS_IMMEDIATE(nr)) {
asm volatile(LOCK_PREFIX "orb %1,%0" : CONST_MASK_ADDR : "i" (CONST_MASK) : "memory"); asm volatile(LOCK_PREFIX "orb %1,%0"
else : CONST_MASK_ADDR(nr, addr)
asm volatile(LOCK_PREFIX "bts %1,%0" : ADDR : "Ir" (nr) : "memory"); : "i" (CONST_MASK(nr))
: "memory");
} else {
asm volatile(LOCK_PREFIX "bts %1,%0"
: BITOP_ADDR(addr) : "Ir" (nr) : "memory");
}
} }
/** /**
* __set_bit - Set a bit in memory * __set_bit - Set a bit in memory
* @nr: the bit to set * @nr: the bit to set
...@@ -89,10 +92,15 @@ static inline void __set_bit(int nr, volatile unsigned long *addr) ...@@ -89,10 +92,15 @@ static inline void __set_bit(int nr, volatile unsigned long *addr)
*/ */
static inline void clear_bit(int nr, volatile unsigned long *addr) static inline void clear_bit(int nr, volatile unsigned long *addr)
{ {
if (IS_IMMEDIATE(nr)) if (IS_IMMEDIATE(nr)) {
asm volatile(LOCK_PREFIX "andb %1,%0" : CONST_MASK_ADDR : "i" (~CONST_MASK)); asm volatile(LOCK_PREFIX "andb %1,%0"
else : CONST_MASK_ADDR(nr, addr)
asm volatile(LOCK_PREFIX "btr %1,%0" : ADDR : "Ir" (nr)); : "i" (~CONST_MASK(nr)));
} else {
asm volatile(LOCK_PREFIX "btr %1,%0"
: BITOP_ADDR(addr)
: "Ir" (nr));
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment