[PATCH] bitops: remove unused generic bitops in include/linux/bitops.h
[linux-2.6.22.y-op.git] / include / asm-v850 / bitops.h
blob1f6fd5ab4177badda30517f04e339b84a471c144
1 /*
2 * include/asm-v850/bitops.h -- Bit operations
4 * Copyright (C) 2001,02,03,04,05 NEC Electronics Corporation
5 * Copyright (C) 2001,02,03,04,05 Miles Bader <miles@gnu.org>
6 * Copyright (C) 1992 Linus Torvalds.
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of this
10 * archive for more details.
13 #ifndef __V850_BITOPS_H__
14 #define __V850_BITOPS_H__
17 #include <linux/config.h>
18 #include <linux/compiler.h> /* unlikely */
19 #include <asm/byteorder.h> /* swab32 */
20 #include <asm/system.h> /* interrupt enable/disable */
23 #ifdef __KERNEL__
25 #include <asm-generic/bitops/ffz.h>
28 * The __ functions are not atomic
31 /* In the following constant-bit-op macros, a "g" constraint is used when
32 we really need an integer ("i" constraint). This is to avoid
33 warnings/errors from the compiler in the case where the associated
34 operand _isn't_ an integer, and shouldn't produce bogus assembly because
35 use of that form is protected by a guard statement that checks for
36 constants, and should otherwise be removed by the optimizer. This
37 _usually_ works -- however, __builtin_constant_p returns true for a
38 variable with a known constant value too, and unfortunately gcc will
39 happily put the variable in a register and use the register for the "g"
40 constraint'd asm operand. To avoid the latter problem, we add a
41 constant offset to the operand and subtract it back in the asm code;
42 forcing gcc to do arithmetic on the value is usually enough to get it
43 to use a real constant value. This is horrible, and ultimately
44 unreliable too, but it seems to work for now (hopefully gcc will offer
45 us more control in the future, so we can do a better job). */
47 #define __const_bit_op(op, nr, addr) \
48 ({ __asm__ (op " (%0 - 0x123), %1" \
49 :: "g" (((nr) & 0x7) + 0x123), \
50 "m" (*((char *)(addr) + ((nr) >> 3))) \
51 : "memory"); })
52 #define __var_bit_op(op, nr, addr) \
53 ({ int __nr = (nr); \
54 __asm__ (op " %0, [%1]" \
55 :: "r" (__nr & 0x7), \
56 "r" ((char *)(addr) + (__nr >> 3)) \
57 : "memory"); })
58 #define __bit_op(op, nr, addr) \
59 ((__builtin_constant_p (nr) && (unsigned)(nr) <= 0x7FFFF) \
60 ? __const_bit_op (op, nr, addr) \
61 : __var_bit_op (op, nr, addr))
63 #define __set_bit(nr, addr) __bit_op ("set1", nr, addr)
64 #define __clear_bit(nr, addr) __bit_op ("clr1", nr, addr)
65 #define __change_bit(nr, addr) __bit_op ("not1", nr, addr)
67 /* The bit instructions used by `non-atomic' variants are actually atomic. */
68 #define set_bit __set_bit
69 #define clear_bit __clear_bit
70 #define change_bit __change_bit
73 #define __const_tns_bit_op(op, nr, addr) \
74 ({ int __tns_res; \
75 __asm__ __volatile__ ( \
76 "tst1 (%1 - 0x123), %2; setf nz, %0; " op " (%1 - 0x123), %2" \
77 : "=&r" (__tns_res) \
78 : "g" (((nr) & 0x7) + 0x123), \
79 "m" (*((char *)(addr) + ((nr) >> 3))) \
80 : "memory"); \
81 __tns_res; \
83 #define __var_tns_bit_op(op, nr, addr) \
84 ({ int __nr = (nr); \
85 int __tns_res; \
86 __asm__ __volatile__ ( \
87 "tst1 %1, [%2]; setf nz, %0; " op " %1, [%2]" \
88 : "=&r" (__tns_res) \
89 : "r" (__nr & 0x7), \
90 "r" ((char *)(addr) + (__nr >> 3)) \
91 : "memory"); \
92 __tns_res; \
94 #define __tns_bit_op(op, nr, addr) \
95 ((__builtin_constant_p (nr) && (unsigned)(nr) <= 0x7FFFF) \
96 ? __const_tns_bit_op (op, nr, addr) \
97 : __var_tns_bit_op (op, nr, addr))
98 #define __tns_atomic_bit_op(op, nr, addr) \
99 ({ int __tns_atomic_res, __tns_atomic_flags; \
100 local_irq_save (__tns_atomic_flags); \
101 __tns_atomic_res = __tns_bit_op (op, nr, addr); \
102 local_irq_restore (__tns_atomic_flags); \
103 __tns_atomic_res; \
106 #define __test_and_set_bit(nr, addr) __tns_bit_op ("set1", nr, addr)
107 #define test_and_set_bit(nr, addr) __tns_atomic_bit_op ("set1", nr, addr)
109 #define __test_and_clear_bit(nr, addr) __tns_bit_op ("clr1", nr, addr)
110 #define test_and_clear_bit(nr, addr) __tns_atomic_bit_op ("clr1", nr, addr)
112 #define __test_and_change_bit(nr, addr) __tns_bit_op ("not1", nr, addr)
113 #define test_and_change_bit(nr, addr) __tns_atomic_bit_op ("not1", nr, addr)
116 #define __const_test_bit(nr, addr) \
117 ({ int __test_bit_res; \
118 __asm__ __volatile__ ("tst1 (%1 - 0x123), %2; setf nz, %0" \
119 : "=r" (__test_bit_res) \
120 : "g" (((nr) & 0x7) + 0x123), \
121 "m" (*((const char *)(addr) + ((nr) >> 3)))); \
122 __test_bit_res; \
124 static inline int __test_bit (int nr, const void *addr)
126 int res;
127 __asm__ __volatile__ ("tst1 %1, [%2]; setf nz, %0"
128 : "=r" (res)
129 : "r" (nr & 0x7), "r" (addr + (nr >> 3)));
130 return res;
132 #define test_bit(nr,addr) \
133 ((__builtin_constant_p (nr) && (unsigned)(nr) <= 0x7FFFF) \
134 ? __const_test_bit ((nr), (addr)) \
135 : __test_bit ((nr), (addr)))
138 /* clear_bit doesn't provide any barrier for the compiler. */
139 #define smp_mb__before_clear_bit() barrier ()
140 #define smp_mb__after_clear_bit() barrier ()
142 #include <asm-generic/bitops/ffs.h>
143 #include <asm-generic/bitops/fls.h>
144 #include <asm-generic/bitops/fls64.h>
145 #include <asm-generic/bitops/__ffs.h>
146 #include <asm-generic/bitops/find.h>
147 #include <asm-generic/bitops/sched.h>
148 #include <asm-generic/bitops/hweight.h>
150 #include <asm-generic/bitops/ext2-non-atomic.h>
151 #define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a)
152 #define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)
154 #include <asm-generic/bitops/minix.h>
156 #endif /* __KERNEL__ */
158 #endif /* __V850_BITOPS_H__ */