Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / include / bits / strings.h
1 #ifndef _BITS_STRINGS_H
2 #define _BITS_STRINGS_H
3
4 FILE_LICENCE ( GPL2_OR_LATER );
5
6 /**
7  * Find last (i.e. most significant) set bit
8  *
9  * @v value             Value
10  * @ret msb             Most significant bit set in value (LSB=1), or zero
11  */
12 static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
13         long msb_minus_one;
14
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.
20          */
21         if ( value ) {
22                 __asm__ ( "bsrl %1, %0"
23                           : "=r" ( msb_minus_one )
24                           : "rm" ( value ) );
25                 return ( msb_minus_one + 1 );
26         } else {
27                 return 0;
28         }
29 }
30
31 /**
32  * Find last (i.e. most significant) set bit
33  *
34  * @v value             Value
35  * @ret msb             Most significant bit set in value (LSB=1), or zero
36  */
37 static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
38         unsigned long high = ( value >> 32 );
39         unsigned long low = ( value >> 0 );
40
41         if ( high ) {
42                 return ( 32 + __flsl ( high ) );
43         } else if ( low ) {
44                 return ( __flsl ( low ) );
45         } else {
46                 return 0;
47         }
48 }
49
50 #endif /* _BITS_STRINGS_H */