- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# arch/avr32/include/arch/bitops.h

Go to the documentation of this file.

    00001
    00041 #ifndef ARCH_BITOPS_H_INCLUDED
    00042 #define ARCH_BITOPS_H_INCLUDED
    00043
    00044 #include <compiler.h>
    00045
    00049 static inline void atomic_set_bit(unsigned int nr, unsigned long *bitmap)
    00050 {
    00051         __sync_or_and_fetch(&bitmap[bit_word(nr)], bit_mask(nr));
    00052 }
    00053
    00057 static inline void atomic_clear_bit(unsigned int nr, unsigned long *bitmap)
    00058 {
    00059         __sync_and_and_fetch(&bitmap[bit_word(nr)], ~bit_mask(nr));
    00060 }
    00061
    00065 static inline void atomic_toggle_bit(unsigned int nr, unsigned long *bitmap)
    00066 {
    00067         __sync_xor_and_fetch(&bitmap[bit_word(nr)], bit_mask(nr));
    00068 }
    00069
    00074 static inline bool atomic_test_and_set_bit(unsigned int nr,
    00075                 unsigned long *bitmap)
    00076 {
    00077         unsigned long tmp;
    00078
    00079         tmp = __sync_fetch_and_or(&bitmap[bit_word(nr)], bit_mask(nr));
    00080
    00081         return 1UL & (tmp >> (nr & (BITS_PER_LONG - 1)));
    00082 }
    00083
    00088 static inline bool atomic_test_and_clear_bit(unsigned int nr,
    00089                 unsigned long *bitmap)
    00090 {
    00091         unsigned long tmp;
    00092
    00093         tmp = __sync_fetch_and_and(&bitmap[bit_word(nr)], ~bit_mask(nr));
    00094
    00095         return 1UL & (tmp >> (nr & (BITS_PER_LONG - 1)));
    00096 }
    00097
    00106 static inline unsigned long __ffs(unsigned long word)
    00107 {
    00108         return count_leading_zeroes(bit_reverse(word));
    00109 }
    00110
    00119 static inline unsigned long ffz(unsigned long word)
    00120 {
    00121         return __ffs(~word);
    00122 }
    00123
    00132 static inline int __fls(unsigned long word)
    00133 {
    00134         return 31 - count_leading_zeroes(word);
    00135 }
    00136
    00147 static inline int fls(unsigned long word)
    00148 {
    00149         if (word == 0)
    00150                 return 0;
    00151
    00152         return __fls(word) + 1;
    00153 }
    00154
    00165 static inline int ffs(unsigned long word)
    00166 {
    00167         if (word == 0)
    00168                 return 0;
    00169         return __ffs(word) + 1;
    00170 }
    00171
    00172 #endif /* ARCH_BITOPS_H_INCLUDED */