1 #ifndef _BITS_STRINGS_H
2 #define _BITS_STRINGS_H
4 FILE_LICENCE ( GPL2_OR_LATER );
7 * Find last (i.e. most significant) set bit
10 * @ret msb Most significant bit set in value (LSB=1), or zero
12 static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
15 /* If the input value is zero, the BSR instruction returns
16 * ZF=1 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__ ( "bsrl %1, %0"
23 : "=r" ( msb_minus_one )
25 return ( msb_minus_one + 1 );
32 * Find last (i.e. most significant) set bit
35 * @ret msb Most significant bit set in value (LSB=1), or zero
37 static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
38 unsigned long high = ( value >> 32 );
39 unsigned long low = ( value >> 0 );
42 return ( 32 + __flsl ( high ) );
44 return ( __flsl ( low ) );
50 #endif /* _BITS_STRINGS_H */