1 // Bit manipulation functions. These functions are not privileged.
3 #ifndef _LL_ARCH_BITOPS_H
4 #define _LL_ARCH_BITOPS_H
6 // Find First Set, counting from 0, undefined if no bits set
7 static inline int ll_ffs(unsigned long val)
10 asm("bsfl %1, %0" : "=r" (ret) : "r" (val));
14 // Find Last Set, counting from 0, undefined if no bits set
15 static inline int ll_fls(unsigned long val)
18 asm("bsrl %1, %0" : "=r" (ret) : "r" (val));
22 // As above, but on 64-bit values, regardless of sizeof(long)
23 static inline int ll_ffs64(uint64_t val)
26 return ll_ffs((uint32_t)val);
28 return ll_ffs((uint32_t)(val >> 32));
31 static inline int ll_fls64(uint64_t val)
33 if ((uint32_t)(val >> 32))
34 return ll_ffs((uint32_t)(val >> 32));
36 return ll_ffs((uint32_t)val);
39 // Set/Clear the nth bit in a multiword bitmap. These functions
40 // are endian and word-size dependent.
42 static inline void ll_multiword_set_bit(unsigned long *bitmap, int bit)
44 asm("bts %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory");
47 static inline void ll_multiword_clear_bit(unsigned long *bitmap, int bit)
49 asm("btr %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory");