iPXE
strings.h
Go to the documentation of this file.
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 __ffsl ( long value ) {
13  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__ ( "bsfl %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 __ffsll ( long long value ){
38  unsigned long high = ( value >> 32 );
39  unsigned long low = ( value >> 0 );
40 
41  if ( low ) {
42  return ( __ffsl ( low ) );
43  } else if ( high ) {
44  return ( 32 + __ffsl ( high ) );
45  } else {
46  return 0;
47  }
48 }
49 
50 /**
51  * Find last (i.e. most significant) set bit
52  *
53  * @v value Value
54  * @ret msb Most significant bit set in value (LSB=1), or zero
55  */
56 static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
57  long msb_minus_one;
58 
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.
64  */
65  if ( value ) {
66  __asm__ ( "bsrl %1, %0"
67  : "=r" ( msb_minus_one )
68  : "rm" ( value ) );
69  return ( msb_minus_one + 1 );
70  } else {
71  return 0;
72  }
73 }
74 
75 /**
76  * Find last (i.e. most significant) set bit
77  *
78  * @v value Value
79  * @ret msb Most significant bit set in value (LSB=1), or zero
80  */
81 static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
82  unsigned long high = ( value >> 32 );
83  unsigned long low = ( value >> 0 );
84 
85  if ( high ) {
86  return ( 32 + __flsl ( high ) );
87  } else if ( low ) {
88  return ( __flsl ( low ) );
89  } else {
90  return 0;
91  }
92 }
93 
94 #endif /* _BITS_STRINGS_H */
uint32_t low
Low 16 bits of address.
Definition: myson.h:19
static __attribute__((always_inline)) int __ffsl(long value)
Find first (i.e.
Definition: strings.h:12
int __flsl(long x)
int __flsll(long long x)
int __ffsl(long x)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t high
High 32 bits of address.
Definition: myson.h:20
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
int __ffsll(long long x)