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 __ffsl ( long value ) {
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__ ( "bsfl %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 __ffsll ( long long value ){
38 unsigned long high = ( value >> 32 );
39 unsigned long low = ( value >> 0 );
42 return ( __ffsl ( low ) );
44 return ( 32 + __ffsl ( high ) );
51 * Find last (i.e. most significant) set bit
54 * @ret msb Most significant bit set in value (LSB=1), or zero
56 static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
59 /* If the input value is zero, the BSR instruction returns
60 * ZF=0 and leaves an undefined value in the output register.
61 * Perform this check in C rather than asm so that it can be
62 * omitted in cases where the compiler is able to prove that
63 * the input is non-zero.
66 __asm__ ( "bsrl %1, %0"
67 : "=r" ( msb_minus_one )
69 return ( msb_minus_one + 1 );
76 * Find last (i.e. most significant) set bit
79 * @ret msb Most significant bit set in value (LSB=1), or zero
81 static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
82 unsigned long high = ( value >> 32 );
83 unsigned long low = ( value >> 0 );
86 return ( 32 + __flsl ( high ) );
88 return ( __flsl ( low ) );
94 #endif /* _BITS_STRINGS_H */