aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/bitops
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2007-10-19 02:40:31 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 14:53:42 -0400
commitd05be13bcc6ec615fb2e9556a9b85d52800669b6 (patch)
treee75cee7b28e2a22d94f29fdd44746ea14f4fc6b8 /include/asm-generic/bitops
parent5159f40742508e03aed4273a9b3ef06f4e71929f (diff)
define first set of BIT* macros
define first set of BIT* macros - move BITOP_MASK and BITOP_WORD from asm-generic/bitops/atomic.h to include/linux/bitops.h and rename it to BIT_MASK and BIT_WORD - move BITS_TO_LONGS and BITS_PER_BYTE to bitops.h too and allow easily define another BITS_TO_something (e.g. in event.c) by BITS_TO_TYPE macro Remaining (and common) BIT macro will be defined after all occurences and conflicts will be sorted out in the patches. Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/asm-generic/bitops')
-rw-r--r--include/asm-generic/bitops/atomic.h27
-rw-r--r--include/asm-generic/bitops/non-atomic.h29
2 files changed, 25 insertions, 31 deletions
diff --git a/include/asm-generic/bitops/atomic.h b/include/asm-generic/bitops/atomic.h
index cd8a9641bd66..4657f3e410fc 100644
--- a/include/asm-generic/bitops/atomic.h
+++ b/include/asm-generic/bitops/atomic.h
@@ -3,9 +3,6 @@
3 3
4#include <asm/types.h> 4#include <asm/types.h>
5 5
6#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
7#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
8
9#ifdef CONFIG_SMP 6#ifdef CONFIG_SMP
10#include <asm/spinlock.h> 7#include <asm/spinlock.h>
11#include <asm/cache.h> /* we use L1_CACHE_BYTES */ 8#include <asm/cache.h> /* we use L1_CACHE_BYTES */
@@ -66,8 +63,8 @@ extern raw_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned;
66 */ 63 */
67static inline void set_bit(int nr, volatile unsigned long *addr) 64static inline void set_bit(int nr, volatile unsigned long *addr)
68{ 65{
69 unsigned long mask = BITOP_MASK(nr); 66 unsigned long mask = BIT_MASK(nr);
70 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 67 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
71 unsigned long flags; 68 unsigned long flags;
72 69
73 _atomic_spin_lock_irqsave(p, flags); 70 _atomic_spin_lock_irqsave(p, flags);
@@ -87,8 +84,8 @@ static inline void set_bit(int nr, volatile unsigned long *addr)
87 */ 84 */
88static inline void clear_bit(int nr, volatile unsigned long *addr) 85static inline void clear_bit(int nr, volatile unsigned long *addr)
89{ 86{
90 unsigned long mask = BITOP_MASK(nr); 87 unsigned long mask = BIT_MASK(nr);
91 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 88 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
92 unsigned long flags; 89 unsigned long flags;
93 90
94 _atomic_spin_lock_irqsave(p, flags); 91 _atomic_spin_lock_irqsave(p, flags);
@@ -108,8 +105,8 @@ static inline void clear_bit(int nr, volatile unsigned long *addr)
108 */ 105 */
109static inline void change_bit(int nr, volatile unsigned long *addr) 106static inline void change_bit(int nr, volatile unsigned long *addr)
110{ 107{
111 unsigned long mask = BITOP_MASK(nr); 108 unsigned long mask = BIT_MASK(nr);
112 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 109 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
113 unsigned long flags; 110 unsigned long flags;
114 111
115 _atomic_spin_lock_irqsave(p, flags); 112 _atomic_spin_lock_irqsave(p, flags);
@@ -128,8 +125,8 @@ static inline void change_bit(int nr, volatile unsigned long *addr)
128 */ 125 */
129static inline int test_and_set_bit(int nr, volatile unsigned long *addr) 126static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
130{ 127{
131 unsigned long mask = BITOP_MASK(nr); 128 unsigned long mask = BIT_MASK(nr);
132 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 129 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
133 unsigned long old; 130 unsigned long old;
134 unsigned long flags; 131 unsigned long flags;
135 132
@@ -152,8 +149,8 @@ static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
152 */ 149 */
153static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) 150static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
154{ 151{
155 unsigned long mask = BITOP_MASK(nr); 152 unsigned long mask = BIT_MASK(nr);
156 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 153 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
157 unsigned long old; 154 unsigned long old;
158 unsigned long flags; 155 unsigned long flags;
159 156
@@ -175,8 +172,8 @@ static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
175 */ 172 */
176static inline int test_and_change_bit(int nr, volatile unsigned long *addr) 173static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
177{ 174{
178 unsigned long mask = BITOP_MASK(nr); 175 unsigned long mask = BIT_MASK(nr);
179 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 176 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
180 unsigned long old; 177 unsigned long old;
181 unsigned long flags; 178 unsigned long flags;
182 179
diff --git a/include/asm-generic/bitops/non-atomic.h b/include/asm-generic/bitops/non-atomic.h
index 46a825cf2ae1..697cc2b7e0f0 100644
--- a/include/asm-generic/bitops/non-atomic.h
+++ b/include/asm-generic/bitops/non-atomic.h
@@ -3,9 +3,6 @@
3 3
4#include <asm/types.h> 4#include <asm/types.h>
5 5
6#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
7#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
8
9/** 6/**
10 * __set_bit - Set a bit in memory 7 * __set_bit - Set a bit in memory
11 * @nr: the bit to set 8 * @nr: the bit to set
@@ -17,16 +14,16 @@
17 */ 14 */
18static inline void __set_bit(int nr, volatile unsigned long *addr) 15static inline void __set_bit(int nr, volatile unsigned long *addr)
19{ 16{
20 unsigned long mask = BITOP_MASK(nr); 17 unsigned long mask = BIT_MASK(nr);
21 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 18 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
22 19
23 *p |= mask; 20 *p |= mask;
24} 21}
25 22
26static inline void __clear_bit(int nr, volatile unsigned long *addr) 23static inline void __clear_bit(int nr, volatile unsigned long *addr)
27{ 24{
28 unsigned long mask = BITOP_MASK(nr); 25 unsigned long mask = BIT_MASK(nr);
29 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 26 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
30 27
31 *p &= ~mask; 28 *p &= ~mask;
32} 29}
@@ -42,8 +39,8 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr)
42 */ 39 */
43static inline void __change_bit(int nr, volatile unsigned long *addr) 40static inline void __change_bit(int nr, volatile unsigned long *addr)
44{ 41{
45 unsigned long mask = BITOP_MASK(nr); 42 unsigned long mask = BIT_MASK(nr);
46 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 43 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
47 44
48 *p ^= mask; 45 *p ^= mask;
49} 46}
@@ -59,8 +56,8 @@ static inline void __change_bit(int nr, volatile unsigned long *addr)
59 */ 56 */
60static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 57static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
61{ 58{
62 unsigned long mask = BITOP_MASK(nr); 59 unsigned long mask = BIT_MASK(nr);
63 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 60 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
64 unsigned long old = *p; 61 unsigned long old = *p;
65 62
66 *p = old | mask; 63 *p = old | mask;
@@ -78,8 +75,8 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
78 */ 75 */
79static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 76static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
80{ 77{
81 unsigned long mask = BITOP_MASK(nr); 78 unsigned long mask = BIT_MASK(nr);
82 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 79 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
83 unsigned long old = *p; 80 unsigned long old = *p;
84 81
85 *p = old & ~mask; 82 *p = old & ~mask;
@@ -90,8 +87,8 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
90static inline int __test_and_change_bit(int nr, 87static inline int __test_and_change_bit(int nr,
91 volatile unsigned long *addr) 88 volatile unsigned long *addr)
92{ 89{
93 unsigned long mask = BITOP_MASK(nr); 90 unsigned long mask = BIT_MASK(nr);
94 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 91 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
95 unsigned long old = *p; 92 unsigned long old = *p;
96 93
97 *p = old ^ mask; 94 *p = old ^ mask;
@@ -105,7 +102,7 @@ static inline int __test_and_change_bit(int nr,
105 */ 102 */
106static inline int test_bit(int nr, const volatile unsigned long *addr) 103static inline int test_bit(int nr, const volatile unsigned long *addr)
107{ 104{
108 return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 105 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
109} 106}
110 107
111#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */ 108#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */