1 #ifndef _ASM_GENERIC_BITOPS_H_
2 #define _ASM_GENERIC_BITOPS_H_
5 * For the benefit of those who are trying to port Linux to another
6 * architecture, here are some C-language equivalents. You should
7 * recode these in the native assembly language, if at all possible.
8 * To guarantee atomicity, these routines call cli() and sti() to
9 * disable interrupts while they operate. (You have to provide inline
10 * routines to cli() and sti().)
12 * Also note, these routines assume that you have 32 bit longs.
13 * You will have to change this if you are trying to port Linux to the
14 * Alpha architecture or to a Cray. :-)
16 * C language equivalents written by Theodore Ts'o, 9/26/92
19 extern __inline__ int set_bit(int nr,long * addr)
24 mask = 1 << (nr & 0x1f);
26 retval = (mask & *addr) != 0;
32 extern __inline__ int clear_bit(int nr, long * addr)
37 mask = 1 << (nr & 0x1f);
39 retval = (mask & *addr) != 0;
45 extern __inline__ int test_bit(int nr, const unsigned long * addr)
50 mask = 1 << (nr & 0x1f);
51 return ((mask & *addr) != 0);
55 * fls: find last bit set.
58 #define fls(x) generic_fls(x)
59 #define fls64(x) generic_fls64(x)
64 * ffs: find first bit set. This is defined the same way as
65 * the libc and compiler builtin ffs routines, therefore
66 * differs in spirit from the above ffz (man ffs).
69 #define ffs(x) generic_ffs(x)
72 * hweightN: returns the hamming weight (i.e. the number
73 * of bits set) of a N-bit word
76 #define hweight32(x) generic_hweight32(x)
77 #define hweight16(x) generic_hweight16(x)
78 #define hweight8(x) generic_hweight8(x)
80 #endif /* __KERNEL__ */
82 #endif /* _ASM_GENERIC_BITOPS_H */