Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / include / asm-arm / bitops.h
index 4edd4dc..0ac54b1 100644 (file)
 
 #ifdef __KERNEL__
 
+#include <linux/compiler.h>
 #include <asm/system.h>
 
-#define smp_mb__before_clear_bit()     do { } while (0)
-#define smp_mb__after_clear_bit()      do { } while (0)
+#define smp_mb__before_clear_bit()     mb()
+#define smp_mb__after_clear_bit()      mb()
 
 /*
  * These functions are the basis of our bit ops.
@@ -116,65 +117,7 @@ ____atomic_test_and_change_bit(unsigned int bit, volatile unsigned long *p)
        return res & mask;
 }
 
-/*
- * Now the non-atomic variants.  We let the compiler handle all
- * optimisations for these.  These are all _native_ endian.
- */
-static inline void __set_bit(int nr, volatile unsigned long *p)
-{
-       p[nr >> 5] |= (1UL << (nr & 31));
-}
-
-static inline void __clear_bit(int nr, volatile unsigned long *p)
-{
-       p[nr >> 5] &= ~(1UL << (nr & 31));
-}
-
-static inline void __change_bit(int nr, volatile unsigned long *p)
-{
-       p[nr >> 5] ^= (1UL << (nr & 31));
-}
-
-static inline int __test_and_set_bit(int nr, volatile unsigned long *p)
-{
-       unsigned long oldval, mask = 1UL << (nr & 31);
-
-       p += nr >> 5;
-
-       oldval = *p;
-       *p = oldval | mask;
-       return oldval & mask;
-}
-
-static inline int __test_and_clear_bit(int nr, volatile unsigned long *p)
-{
-       unsigned long oldval, mask = 1UL << (nr & 31);
-
-       p += nr >> 5;
-
-       oldval = *p;
-       *p = oldval & ~mask;
-       return oldval & mask;
-}
-
-static inline int __test_and_change_bit(int nr, volatile unsigned long *p)
-{
-       unsigned long oldval, mask = 1UL << (nr & 31);
-
-       p += nr >> 5;
-
-       oldval = *p;
-       *p = oldval ^ mask;
-       return oldval & mask;
-}
-
-/*
- * This routine doesn't need to be atomic.
- */
-static inline int __test_bit(int nr, const volatile unsigned long * p)
-{
-       return (p[nr >> 5] >> (nr & 31)) & 1UL;
-}
+#include <asm-generic/bitops/non-atomic.h>
 
 /*
  *  A note about Endian-ness.
@@ -229,6 +172,7 @@ extern int _find_next_zero_bit_be(const void * p, int size, int offset);
 extern int _find_first_bit_be(const unsigned long *p, unsigned size);
 extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
 
+#ifndef CONFIG_SMP
 /*
  * The __* form of bitops are non-atomic and may be reordered.
  */
@@ -241,6 +185,10 @@ extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
        (__builtin_constant_p(nr) ?             \
         ____atomic_##name(nr, p) :             \
         _##name##_be(nr,p))
+#else
+#define ATOMIC_BITOP_LE(name,nr,p)     _##name##_le(nr,p)
+#define ATOMIC_BITOP_BE(name,nr,p)     _##name##_be(nr,p)
+#endif
 
 #define NONATOMIC_BITOP(name,nr,p)             \
        (____nonatomic_##name(nr, p))
@@ -255,7 +203,6 @@ extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
 #define test_and_set_bit(nr,p)         ATOMIC_BITOP_LE(test_and_set_bit,nr,p)
 #define test_and_clear_bit(nr,p)       ATOMIC_BITOP_LE(test_and_clear_bit,nr,p)
 #define test_and_change_bit(nr,p)      ATOMIC_BITOP_LE(test_and_change_bit,nr,p)
-#define test_bit(nr,p)                 __test_bit(nr,p)
 #define find_first_zero_bit(p,sz)      _find_first_zero_bit_le(p,sz)
 #define find_next_zero_bit(p,sz,off)   _find_next_zero_bit_le(p,sz,off)
 #define find_first_bit(p,sz)           _find_first_bit_le(p,sz)
@@ -274,7 +221,6 @@ extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
 #define test_and_set_bit(nr,p)         ATOMIC_BITOP_BE(test_and_set_bit,nr,p)
 #define test_and_clear_bit(nr,p)       ATOMIC_BITOP_BE(test_and_clear_bit,nr,p)
 #define test_and_change_bit(nr,p)      ATOMIC_BITOP_BE(test_and_change_bit,nr,p)
-#define test_bit(nr,p)                 __test_bit(nr,p)
 #define find_first_zero_bit(p,sz)      _find_first_zero_bit_be(p,sz)
 #define find_next_zero_bit(p,sz,off)   _find_next_zero_bit_be(p,sz,off)
 #define find_first_bit(p,sz)           _find_first_bit_be(p,sz)
@@ -286,65 +232,49 @@ extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
 
 #if __LINUX_ARM_ARCH__ < 5
 
-/*
- * ffz = Find First Zero in word. Undefined if no zero exists,
- * so code should check against ~0UL first..
- */
-static inline unsigned long ffz(unsigned long word)
-{
-       int k;
-
-       word = ~word;
-       k = 31;
-       if (word & 0x0000ffff) { k -= 16; word <<= 16; }
-       if (word & 0x00ff0000) { k -= 8;  word <<= 8;  }
-       if (word & 0x0f000000) { k -= 4;  word <<= 4;  }
-       if (word & 0x30000000) { k -= 2;  word <<= 2;  }
-       if (word & 0x40000000) { k -= 1; }
-        return k;
-}
-
-/*
- * ffz = Find First Zero in word. Undefined if no zero exists,
- * so code should check against ~0UL first..
- */
-static inline unsigned long __ffs(unsigned long word)
-{
-       int k;
-
-       k = 31;
-       if (word & 0x0000ffff) { k -= 16; word <<= 16; }
-       if (word & 0x00ff0000) { k -= 8;  word <<= 8;  }
-       if (word & 0x0f000000) { k -= 4;  word <<= 4;  }
-       if (word & 0x30000000) { k -= 2;  word <<= 2;  }
-       if (word & 0x40000000) { k -= 1; }
-        return k;
-}
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/ffs.h>
 
-/*
- * fls: find last bit set.
- */
-
-#define fls(x) generic_fls(x)
-
-/*
- * ffs: find first bit set. This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
+#else
 
-#define ffs(x) generic_ffs(x)
+static inline int constant_fls(int x)
+{
+       int r = 32;
 
-#else
+       if (!x)
+               return 0;
+       if (!(x & 0xffff0000u)) {
+               x <<= 16;
+               r -= 16;
+       }
+       if (!(x & 0xff000000u)) {
+               x <<= 8;
+               r -= 8;
+       }
+       if (!(x & 0xf0000000u)) {
+               x <<= 4;
+               r -= 4;
+       }
+       if (!(x & 0xc0000000u)) {
+               x <<= 2;
+               r -= 2;
+       }
+       if (!(x & 0x80000000u)) {
+               x <<= 1;
+               r -= 1;
+       }
+       return r;
+}
 
 /*
  * On ARMv5 and above those functions can be implemented around
  * the clz instruction for much better code efficiency.
  */
 
-static __inline__ int generic_fls(int x);
 #define fls(x) \
-       ( __builtin_constant_p(x) ? generic_fls(x) : \
+       ( __builtin_constant_p(x) ? constant_fls(x) : \
          ({ int __r; asm("clz\t%0, %1" : "=r"(__r) : "r"(x) : "cc"); 32-__r; }) )
 #define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
 #define __ffs(x) (ffs(x) - 1)
@@ -352,30 +282,10 @@ static __inline__ int generic_fls(int x);
 
 #endif
 
-/*
- * Find first bit set in a 168-bit bitmap, where the first
- * 128 bits are unlikely to be set.
- */
-static inline int sched_find_first_bit(const unsigned long *b)
-{
-       unsigned long v;
-       unsigned int off;
-
-       for (off = 0; v = b[off], off < 4; off++) {
-               if (unlikely(v))
-                       break;
-       }
-       return __ffs(v) + off * 32;
-}
-
-/*
- * hweightN: returns the hamming weight (i.e. the number
- * of bits set) of a N-bit word
- */
+#include <asm-generic/bitops/fls64.h>
 
-#define hweight32(x) generic_hweight32(x)
-#define hweight16(x) generic_hweight16(x)
-#define hweight8(x) generic_hweight8(x)
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/hweight.h>
 
 /*
  * Ext2 is defined to use little-endian byte ordering.
@@ -390,7 +300,7 @@ static inline int sched_find_first_bit(const unsigned long *b)
 #define ext2_clear_bit_atomic(lock,nr,p)        \
                 test_and_clear_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define ext2_test_bit(nr,p)                    \
-               __test_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
+               test_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define ext2_find_first_zero_bit(p,sz)         \
                _find_first_zero_bit_le(p,sz)
 #define ext2_find_next_zero_bit(p,sz,off)      \
@@ -403,7 +313,7 @@ static inline int sched_find_first_bit(const unsigned long *b)
 #define minix_set_bit(nr,p)                    \
                __set_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define minix_test_bit(nr,p)                   \
-               __test_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
+               test_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define minix_test_and_set_bit(nr,p)           \
                __test_and_set_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define minix_test_and_clear_bit(nr,p)         \