These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / x86_64 / include / bits / strings.h
1 #ifndef _BITS_STRINGS_H
2 #define _BITS_STRINGS_H
3
4 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
6 /**
7  * Find first (i.e. least significant) set bit
8  *
9  * @v value             Value
10  * @ret lsb             Least significant bit set in value (LSB=1), or zero
11  */
12 static inline __attribute__ (( always_inline )) int __ffsll ( long long value ){
13         long long lsb_minus_one;
14
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.
20          */
21         if ( value ) {
22                 __asm__ ( "bsfq %1, %0"
23                           : "=r" ( lsb_minus_one )
24                           : "rm" ( value ) );
25                 return ( lsb_minus_one + 1 );
26         } else {
27                 return 0;
28         }
29 }
30
31 /**
32  * Find first (i.e. least significant) set bit
33  *
34  * @v value             Value
35  * @ret lsb             Least significant bit set in value (LSB=1), or zero
36  */
37 static inline __attribute__ (( always_inline )) int __ffsl ( long value ) {
38
39         return __ffsll ( value );
40 }
41
42 /**
43  * Find last (i.e. most significant) set bit
44  *
45  * @v value             Value
46  * @ret msb             Most significant bit set in value (LSB=1), or zero
47  */
48 static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
49         long long msb_minus_one;
50
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.
56          */
57         if ( value ) {
58                 __asm__ ( "bsrq %1, %0"
59                           : "=r" ( msb_minus_one )
60                           : "rm" ( value ) );
61                 return ( msb_minus_one + 1 );
62         } else {
63                 return 0;
64         }
65 }
66
67 /**
68  * Find last (i.e. most significant) set bit
69  *
70  * @v value             Value
71  * @ret msb             Most significant bit set in value (LSB=1), or zero
72  */
73 static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
74
75         return __flsll ( value );
76 }
77
78 #endif /* _BITS_STRINGS_H */