[NETFILTER]: ipt_TCPMSS: misc cleanup
[hh.org.git] / include / asm-frv / bitops.h
blob980ae1b0cd285a5578075b0d6e82866f5f7ea047
1 /* bitops.h: bit operations for the Fujitsu FR-V CPUs
3 * For an explanation of how atomic ops work in this arch, see:
4 * Documentation/fujitsu/frv/atomic-ops.txt
6 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
7 * Written by David Howells (dhowells@redhat.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 #ifndef _ASM_BITOPS_H
15 #define _ASM_BITOPS_H
17 #include <linux/compiler.h>
18 #include <asm/byteorder.h>
19 #include <asm/system.h>
20 #include <asm/atomic.h>
22 #ifdef __KERNEL__
24 #include <asm-generic/bitops/ffz.h>
27 * clear_bit() doesn't provide any barrier for the compiler.
29 #define smp_mb__before_clear_bit() barrier()
30 #define smp_mb__after_clear_bit() barrier()
32 static inline int test_and_clear_bit(int nr, volatile void *addr)
34 volatile unsigned long *ptr = addr;
35 unsigned long mask = 1UL << (nr & 31);
36 ptr += nr >> 5;
37 return (atomic_test_and_ANDNOT_mask(mask, ptr) & mask) != 0;
40 static inline int test_and_set_bit(int nr, volatile void *addr)
42 volatile unsigned long *ptr = addr;
43 unsigned long mask = 1UL << (nr & 31);
44 ptr += nr >> 5;
45 return (atomic_test_and_OR_mask(mask, ptr) & mask) != 0;
48 static inline int test_and_change_bit(int nr, volatile void *addr)
50 volatile unsigned long *ptr = addr;
51 unsigned long mask = 1UL << (nr & 31);
52 ptr += nr >> 5;
53 return (atomic_test_and_XOR_mask(mask, ptr) & mask) != 0;
56 static inline void clear_bit(int nr, volatile void *addr)
58 test_and_clear_bit(nr, addr);
61 static inline void set_bit(int nr, volatile void *addr)
63 test_and_set_bit(nr, addr);
66 static inline void change_bit(int nr, volatile void * addr)
68 test_and_change_bit(nr, addr);
71 static inline void __clear_bit(int nr, volatile void * addr)
73 volatile unsigned long *a = addr;
74 int mask;
76 a += nr >> 5;
77 mask = 1 << (nr & 31);
78 *a &= ~mask;
81 static inline void __set_bit(int nr, volatile void * addr)
83 volatile unsigned long *a = addr;
84 int mask;
86 a += nr >> 5;
87 mask = 1 << (nr & 31);
88 *a |= mask;
91 static inline void __change_bit(int nr, volatile void *addr)
93 volatile unsigned long *a = addr;
94 int mask;
96 a += nr >> 5;
97 mask = 1 << (nr & 31);
98 *a ^= mask;
101 static inline int __test_and_clear_bit(int nr, volatile void * addr)
103 volatile unsigned long *a = addr;
104 int mask, retval;
106 a += nr >> 5;
107 mask = 1 << (nr & 31);
108 retval = (mask & *a) != 0;
109 *a &= ~mask;
110 return retval;
113 static inline int __test_and_set_bit(int nr, volatile void * addr)
115 volatile unsigned long *a = addr;
116 int mask, retval;
118 a += nr >> 5;
119 mask = 1 << (nr & 31);
120 retval = (mask & *a) != 0;
121 *a |= mask;
122 return retval;
125 static inline int __test_and_change_bit(int nr, volatile void * addr)
127 volatile unsigned long *a = addr;
128 int mask, retval;
130 a += nr >> 5;
131 mask = 1 << (nr & 31);
132 retval = (mask & *a) != 0;
133 *a ^= mask;
134 return retval;
138 * This routine doesn't need to be atomic.
140 static inline int __constant_test_bit(int nr, const volatile void * addr)
142 return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
145 static inline int __test_bit(int nr, const volatile void * addr)
147 int * a = (int *) addr;
148 int mask;
150 a += nr >> 5;
151 mask = 1 << (nr & 0x1f);
152 return ((mask & *a) != 0);
155 #define test_bit(nr,addr) \
156 (__builtin_constant_p(nr) ? \
157 __constant_test_bit((nr),(addr)) : \
158 __test_bit((nr),(addr)))
160 #include <asm-generic/bitops/ffs.h>
161 #include <asm-generic/bitops/__ffs.h>
162 #include <asm-generic/bitops/find.h>
165 * fls: find last bit set.
167 #define fls(x) \
168 ({ \
169 int bit; \
171 asm("scan %1,gr0,%0" : "=r"(bit) : "r"(x)); \
173 bit ? 33 - bit : bit; \
176 #include <asm-generic/bitops/fls64.h>
177 #include <asm-generic/bitops/sched.h>
178 #include <asm-generic/bitops/hweight.h>
180 #include <asm-generic/bitops/ext2-non-atomic.h>
182 #define ext2_set_bit_atomic(lock,nr,addr) test_and_set_bit ((nr) ^ 0x18, (addr))
183 #define ext2_clear_bit_atomic(lock,nr,addr) test_and_clear_bit((nr) ^ 0x18, (addr))
185 #include <asm-generic/bitops/minix-le.h>
187 #endif /* __KERNEL__ */
189 #endif /* _ASM_BITOPS_H */