linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / include / linux / bitops.h
index 053d6e4..208650b 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef _LINUX_BITOPS_H
 #define _LINUX_BITOPS_H
 #include <asm/types.h>
-#include <asm/bitops.h>
 
 /*
  * ffs: find first bit set. This is defined the same way as
@@ -42,7 +41,7 @@ static inline int generic_ffs(int x)
  * fls: find last bit set.
  */
 
-extern __inline__ int generic_fls(int x)
+static __inline__ int generic_fls(int x)
 {
        int r = 32;
 
@@ -71,7 +70,22 @@ extern __inline__ int generic_fls(int x)
        return r;
 }
 
-extern __inline__ int get_bitmask_order(unsigned int count)
+/*
+ * Include this here because some architectures need generic_ffs/fls in
+ * scope
+ */
+#include <asm/bitops.h>
+
+
+static inline int generic_fls64(__u64 x)
+{
+       __u32 h = x >> 32;
+       if (h)
+               return fls(h) + 32;
+       return fls(x);
+}
+
+static __inline__ int get_bitmask_order(unsigned int count)
 {
        int order;
        
@@ -79,6 +93,16 @@ extern __inline__ int get_bitmask_order(unsigned int count)
        return order;   /* We could be slightly more clever with -1 here... */
 }
 
+static __inline__ int get_count_order(unsigned int count)
+{
+       int order;
+       
+       order = fls(count) - 1;
+       if (count & (count - 1))
+               order++;
+       return order;
+}
+
 /*
  * hweightN: returns the hamming weight (i.e. the number
  * of bits set) of a N-bit word
@@ -129,4 +153,26 @@ static inline unsigned long hweight_long(unsigned long w)
        return sizeof(w) == 4 ? generic_hweight32(w) : generic_hweight64(w);
 }
 
+/*
+ * rol32 - rotate a 32-bit value left
+ *
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u32 rol32(__u32 word, unsigned int shift)
+{
+       return (word << shift) | (word >> (32 - shift));
+}
+
+/*
+ * ror32 - rotate a 32-bit value right
+ *
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u32 ror32(__u32 word, unsigned int shift)
+{
+       return (word >> shift) | (word << (32 - shift));
+}
+
 #endif