2 * include/asm-xtensa/bitops.h
4 * Atomic operations that C can't guarantee us.Useful for resource counting etc.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copyright (C) 2001 - 2007 Tensilica Inc.
13 #ifndef _XTENSA_BITOPS_H
14 #define _XTENSA_BITOPS_H
18 #ifndef _LINUX_BITOPS_H
19 #error only <linux/bitops.h> can be included directly
22 #include <asm/processor.h>
23 #include <asm/byteorder.h>
25 #define smp_mb__before_clear_bit() smp_mb()
26 #define smp_mb__after_clear_bit() smp_mb()
28 #include <asm-generic/bitops/non-atomic.h>
32 static inline unsigned long __cntlz (unsigned long x
)
35 asm ("nsau %0, %1" : "=r" (lz
) : "r" (x
));
40 * ffz: Find first zero in word. Undefined if no zero exists.
41 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
44 static inline int ffz(unsigned long x
)
46 return 31 - __cntlz(~x
& -~x
);
50 * __ffs: Find first bit set in word. Return 0 for bit 0
53 static inline int __ffs(unsigned long x
)
55 return 31 - __cntlz(x
& -x
);
59 * ffs: Find first bit set in word. This is defined the same way as
60 * the libc and compiler builtin ffs routines, therefore
61 * differs in spirit from the above ffz (man ffs).
64 static inline int ffs(unsigned long x
)
66 return 32 - __cntlz(x
& -x
);
70 * fls: Find last (most-significant) bit set in word.
71 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
74 static inline int fls (unsigned int x
)
76 return 32 - __cntlz(x
);
80 * __fls - find last (most-significant) set bit in a long word
81 * @word: the word to search
83 * Undefined if no set bit exists, so code should check against 0 first.
85 static inline unsigned long __fls(unsigned long word
)
87 return 31 - __cntlz(word
);
91 /* Use the generic implementation if we don't have the nsa/nsau instructions. */
93 # include <asm-generic/bitops/ffs.h>
94 # include <asm-generic/bitops/__ffs.h>
95 # include <asm-generic/bitops/ffz.h>
96 # include <asm-generic/bitops/fls.h>
97 # include <asm-generic/bitops/__fls.h>
101 #include <asm-generic/bitops/fls64.h>
103 #if XCHAL_HAVE_S32C1I
105 static inline void set_bit(unsigned int bit
, volatile unsigned long *p
)
107 unsigned long tmp
, value
;
108 unsigned long mask
= 1UL << (bit
& 31);
112 __asm__
__volatile__(
113 "1: l32i %1, %3, 0\n"
114 " wsr %1, scompare1\n"
116 " s32c1i %0, %3, 0\n"
118 : "=&a" (tmp
), "=&a" (value
)
119 : "a" (mask
), "a" (p
)
123 static inline void clear_bit(unsigned int bit
, volatile unsigned long *p
)
125 unsigned long tmp
, value
;
126 unsigned long mask
= 1UL << (bit
& 31);
130 __asm__
__volatile__(
131 "1: l32i %1, %3, 0\n"
132 " wsr %1, scompare1\n"
134 " s32c1i %0, %3, 0\n"
136 : "=&a" (tmp
), "=&a" (value
)
137 : "a" (~mask
), "a" (p
)
141 static inline void change_bit(unsigned int bit
, volatile unsigned long *p
)
143 unsigned long tmp
, value
;
144 unsigned long mask
= 1UL << (bit
& 31);
148 __asm__
__volatile__(
149 "1: l32i %1, %3, 0\n"
150 " wsr %1, scompare1\n"
152 " s32c1i %0, %3, 0\n"
154 : "=&a" (tmp
), "=&a" (value
)
155 : "a" (mask
), "a" (p
)
160 test_and_set_bit(unsigned int bit
, volatile unsigned long *p
)
162 unsigned long tmp
, value
;
163 unsigned long mask
= 1UL << (bit
& 31);
167 __asm__
__volatile__(
168 "1: l32i %1, %3, 0\n"
169 " wsr %1, scompare1\n"
171 " s32c1i %0, %3, 0\n"
173 : "=&a" (tmp
), "=&a" (value
)
174 : "a" (mask
), "a" (p
)
181 test_and_clear_bit(unsigned int bit
, volatile unsigned long *p
)
183 unsigned long tmp
, value
;
184 unsigned long mask
= 1UL << (bit
& 31);
188 __asm__
__volatile__(
189 "1: l32i %1, %3, 0\n"
190 " wsr %1, scompare1\n"
192 " s32c1i %0, %3, 0\n"
194 : "=&a" (tmp
), "=&a" (value
)
195 : "a" (~mask
), "a" (p
)
202 test_and_change_bit(unsigned int bit
, volatile unsigned long *p
)
204 unsigned long tmp
, value
;
205 unsigned long mask
= 1UL << (bit
& 31);
209 __asm__
__volatile__(
210 "1: l32i %1, %3, 0\n"
211 " wsr %1, scompare1\n"
213 " s32c1i %0, %3, 0\n"
215 : "=&a" (tmp
), "=&a" (value
)
216 : "a" (mask
), "a" (p
)
224 #include <asm-generic/bitops/atomic.h>
226 #endif /* XCHAL_HAVE_S32C1I */
228 #include <asm-generic/bitops/find.h>
229 #include <asm-generic/bitops/le.h>
231 #include <asm-generic/bitops/ext2-atomic-setbit.h>
233 #include <asm-generic/bitops/hweight.h>
234 #include <asm-generic/bitops/lock.h>
235 #include <asm-generic/bitops/sched.h>
237 #endif /* __KERNEL__ */
239 #endif /* _XTENSA_BITOPS_H */
This page took 0.047767 seconds and 5 git commands to generate.