1 // Bit manipulation functions. These functions are not privileged.
3 #ifndef _LL_ARCH_BITOPS_H
4 #define _LL_ARCH_BITOPS_H
6 // Find First (least-significant) Set, counting from 0,
7 // undefined if no bits set
9 static inline int ll_ffs(unsigned long val)
12 asm("bsfq %1, %0" : "=r" (ret) : "r" (val));
16 // Find Last (most-significant) Set, counting from 0,
17 // undefined if no bits set
19 static inline int ll_fls(unsigned long val)
22 asm("bsrq %1, %0" : "=r" (ret) : "r" (val));
26 // As above, but on 64-bit values, regardless of sizeof(long)
27 static inline int ll_ffs64(uint64_t val)
32 static inline int ll_fls64(uint64_t val)
37 // Set/Clear the nth bit in a multiword bitmap. These functions
38 // are endian and word-size dependent.
40 static inline void ll_multiword_set_bit(unsigned long *bitmap, int bit)
42 asm("bts %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory");
45 static inline void ll_multiword_clear_bit(unsigned long *bitmap, int bit)
47 asm("btr %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory");