1 #ifndef _BITS_STRINGS_H
2 #define _BITS_STRINGS_H
4 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
7 * Find first (i.e. least significant) set bit
10 * @ret lsb Least significant bit set in value (LSB=1), or zero
12 static inline __attribute__ (( always_inline )) int __ffsll ( long long value ){
13 long long lsb_minus_one;
15 /* If the input value is zero, the BSF instruction returns
16 * ZF=0 and leaves an undefined value in the output register.
17 * Perform this check in C rather than asm so that it can be
18 * omitted in cases where the compiler is able to prove that
19 * the input is non-zero.
22 __asm__ ( "bsfq %1, %0"
23 : "=r" ( lsb_minus_one )
25 return ( lsb_minus_one + 1 );
32 * Find first (i.e. least significant) set bit
35 * @ret lsb Least significant bit set in value (LSB=1), or zero
37 static inline __attribute__ (( always_inline )) int __ffsl ( long value ) {
39 return __ffsll ( value );
43 * Find last (i.e. most significant) set bit
46 * @ret msb Most significant bit set in value (LSB=1), or zero
48 static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
49 long long msb_minus_one;
51 /* If the input value is zero, the BSR instruction returns
52 * ZF=0 and leaves an undefined value in the output register.
53 * Perform this check in C rather than asm so that it can be
54 * omitted in cases where the compiler is able to prove that
55 * the input is non-zero.
58 __asm__ ( "bsrq %1, %0"
59 : "=r" ( msb_minus_one )
61 return ( msb_minus_one + 1 );
68 * Find last (i.e. most significant) set bit
71 * @ret msb Most significant bit set in value (LSB=1), or zero
73 static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
75 return __flsll ( value );
78 #endif /* _BITS_STRINGS_H */