Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / include / lwk / bitops.h
1 #ifndef _LWK_BITOPS_H
2 #define _LWK_BITOPS_H
3 #include <arch/types.h>
4
5 /*
6  * Include this here because some architectures need generic_ffs/fls in
7  * scope
8  */
9 #include <arch/bitops.h>
10
11 static __inline__ int get_bitmask_order(unsigned int count)
12 {
13         int order;
14         
15         order = fls(count);
16         return order;   /* We could be slightly more clever with -1 here... */
17 }
18
19 static __inline__ int get_count_order(unsigned int count)
20 {
21         int order;
22         
23         order = fls(count) - 1;
24         if (count & (count - 1))
25                 order++;
26         return order;
27 }
28
29 static inline unsigned long hweight_long(unsigned long w)
30 {
31         return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
32 }
33
34 /*
35  * rol32 - rotate a 32-bit value left
36  *
37  * @word: value to rotate
38  * @shift: bits to roll
39  */
40 static inline __u32 rol32(__u32 word, unsigned int shift)
41 {
42         return (word << shift) | (word >> (32 - shift));
43 }
44
45 /*
46  * ror32 - rotate a 32-bit value right
47  *
48  * @word: value to rotate
49  * @shift: bits to roll
50  */
51 static inline __u32 ror32(__u32 word, unsigned int shift)
52 {
53         return (word >> shift) | (word << (32 - shift));
54 }
55
56 static inline unsigned fls_long(unsigned long l)
57 {
58         if (sizeof(l) == 4)
59                 return fls(l);
60         return fls64(l);
61 }
62
63 #endif