Add more stock U-Boot images
[oweals/u-boot_mod.git] / u-boot / include / linux / bitops.h
1 #ifndef _LINUX_BITOPS_H
2 #define _LINUX_BITOPS_H
3
4 /*
5  * Helper macros
6  */
7 #define BIT(_x)                                 (1 << (_x))
8 #define BITS(_start, _bits)             (((1 << (_bits)) - 1) << _start)
9 #define CHECK_BIT(_var, _pos)   ((_var) & (1 << (_pos)))
10
11 #ifndef __ASSEMBLY__
12 /*
13  * ffs: find first bit set. This is defined the same way as
14  * the libc and compiler builtin ffs routines, therefore
15  * differs in spirit from the above ffz (man ffs).
16  */
17 static inline int generic_ffs(int x)
18 {
19         int r = 1;
20
21         if (!x)
22                 return 0;
23         if (!(x & 0xffff)) {
24                 x >>= 16;
25                 r += 16;
26         }
27         if (!(x & 0xff)) {
28                 x >>= 8;
29                 r += 8;
30         }
31         if (!(x & 0xf)) {
32                 x >>= 4;
33                 r += 4;
34         }
35         if (!(x & 3)) {
36                 x >>= 2;
37                 r += 2;
38         }
39         if (!(x & 1)) {
40                 x >>= 1;
41                 r += 1;
42         }
43         return r;
44 }
45
46 /*
47  * hweightN: returns the hamming weight (i.e. the number
48  * of bits set) of a N-bit word
49  */
50 static inline unsigned int generic_hweight32(unsigned int w)
51 {
52         unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
53         res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
54         res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
55         res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
56         return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
57 }
58
59 static inline unsigned int generic_hweight16(unsigned int w)
60 {
61         unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
62         res = (res & 0x3333) + ((res >> 2) & 0x3333);
63         res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
64         return (res & 0x00FF) + ((res >> 8) & 0x00FF);
65 }
66
67 static inline unsigned int generic_hweight8(unsigned int w)
68 {
69         unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
70         res = (res & 0x33) + ((res >> 2) & 0x33);
71         return (res & 0x0F) + ((res >> 4) & 0x0F);
72 }
73
74 #include <asm/bitops.h>
75
76 #endif /* !__ASSEMBLY__ */
77
78 #endif