iPXE
strings.h
Go to the documentation of this file.
1#ifndef _STRINGS_H
2#define _STRINGS_H
3
4/** @file
5 *
6 * String functions
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <string.h>
14#include <bits/strings.h>
15
16/**
17 * Find first (i.e. least significant) set bit
18 *
19 * @v x Value
20 * @ret lsb Least significant bit set in value (LSB=1), or zero
21 */
22static inline __attribute__ (( always_inline )) int
23__constant_ffsll ( unsigned long long x ) {
24 int r = 0;
25
26 if ( ! ( x & 0x00000000ffffffffULL ) ) {
27 x >>= 32;
28 r += 32;
29 }
30 if ( ! ( x & 0x0000ffffUL ) ) {
31 x >>= 16;
32 r += 16;
33 }
34 if ( ! ( x & 0x00ff ) ) {
35 x >>= 8;
36 r += 8;
37 }
38 if ( ! ( x & 0x0f ) ) {
39 x >>= 4;
40 r += 4;
41 }
42 if ( ! ( x & 0x3 ) ) {
43 x >>= 2;
44 r += 2;
45 }
46 if ( ! ( x & 0x1 ) ) {
47 x >>= 1;
48 r += 1;
49 }
50 return ( x ? ( r + 1 ) : 0 );
51}
52
53/**
54 * Find first (i.e. least significant) set bit
55 *
56 * @v x Value
57 * @ret lsb Least significant bit set in value (LSB=1), or zero
58 */
59static inline __attribute__ (( always_inline )) int
60__constant_ffsl ( unsigned long x ) {
61 return __constant_ffsll ( x );
62}
63
64/**
65 * Find last (i.e. most significant) set bit
66 *
67 * @v x Value
68 * @ret msb Most significant bit set in value (LSB=1), or zero
69 */
70static inline __attribute__ (( always_inline )) int
71__constant_flsll ( unsigned long long x ) {
72 int r = 0;
73
74 if ( x & 0xffffffff00000000ULL ) {
75 x >>= 32;
76 r += 32;
77 }
78 if ( x & 0xffff0000UL ) {
79 x >>= 16;
80 r += 16;
81 }
82 if ( x & 0xff00 ) {
83 x >>= 8;
84 r += 8;
85 }
86 if ( x & 0xf0 ) {
87 x >>= 4;
88 r += 4;
89 }
90 if ( x & 0xc ) {
91 x >>= 2;
92 r += 2;
93 }
94 if ( x & 0x2 ) {
95 x >>= 1;
96 r += 1;
97 }
98 return ( x ? ( r + 1 ) : 0 );
99}
100
101/**
102 * Find last (i.e. most significant) set bit
103 *
104 * @v x Value
105 * @ret msb Most significant bit set in value (LSB=1), or zero
106 */
107static inline __attribute__ (( always_inline )) int
108__constant_flsl ( unsigned long x ) {
109 return __constant_flsll ( x );
110}
111
112int __ffsll ( long long x );
113int __ffsl ( long x );
114int __flsll ( long long x );
115int __flsl ( long x );
116
117/**
118 * Find first (i.e. least significant) set bit
119 *
120 * @v x Value
121 * @ret lsb Least significant bit set in value (LSB=1), or zero
122 */
123#define ffsll( x ) \
124 ( __builtin_constant_p ( x ) ? __constant_ffsll ( x ) : __ffsll ( x ) )
125
126/**
127 * Find first (i.e. least significant) set bit
128 *
129 * @v x Value
130 * @ret lsb Least significant bit set in value (LSB=1), or zero
131 */
132#define ffsl( x ) \
133 ( __builtin_constant_p ( x ) ? __constant_ffsl ( x ) : __ffsl ( x ) )
134
135/**
136 * Find first (i.e. least significant) set bit
137 *
138 * @v x Value
139 * @ret lsb Least significant bit set in value (LSB=1), or zero
140 */
141#define ffs( x ) ffsl ( x )
142
143/**
144 * Find last (i.e. most significant) set bit
145 *
146 * @v x Value
147 * @ret msb Most significant bit set in value (LSB=1), or zero
148 */
149#define flsll( x ) \
150 ( __builtin_constant_p ( x ) ? __constant_flsll ( x ) : __flsll ( x ) )
151
152/**
153 * Find last (i.e. most significant) set bit
154 *
155 * @v x Value
156 * @ret msb Most significant bit set in value (LSB=1), or zero
157 */
158#define flsl( x ) \
159 ( __builtin_constant_p ( x ) ? __constant_flsl ( x ) : __flsl ( x ) )
160
161/**
162 * Find last (i.e. most significant) set bit
163 *
164 * @v x Value
165 * @ret msb Most significant bit set in value (LSB=1), or zero
166 */
167#define fls( x ) flsl ( x )
168
169/**
170 * Copy memory
171 *
172 * @v src Source
173 * @v dest Destination
174 * @v len Length
175 */
176static inline __attribute__ (( always_inline )) void
177bcopy ( const void *src, void *dest, size_t len ) {
178 memmove ( dest, src, len );
179}
180
181/**
182 * Zero memory
183 *
184 * @v dest Destination
185 * @v len Length
186 */
187static inline __attribute__ (( always_inline )) void
188bzero ( void *dest, size_t len ) {
189 memset ( dest, 0, len );
190}
191
192int __pure strcasecmp ( const char *first, const char *second ) __nonnull;
193int __pure strncasecmp ( const char *first, const char *second,
194 size_t max ) __nonnull;
195
196#endif /* _STRINGS_H */
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
static const void * src
Definition string.h:48
#define max(x, y)
Definition ath.h:41
ring len
Length.
Definition dwmac.h:226
#define __nonnull
Declare a function's pointer parameters as non-null - i.e.
Definition compiler.h:592
#define __pure
Declare a function as pure - i.e.
Definition compiler.h:578
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
String functions.
void * memset(void *dest, int character, size_t len) __nonnull
void * memmove(void *dest, const void *src, size_t len) __nonnull
int __pure strcasecmp(const char *first, const char *second) __nonnull
Compare case-insensitive strings.
Definition string.c:209
int __pure strncasecmp(const char *first, const char *second, size_t max) __nonnull
Compare case-insensitive strings.
Definition string.c:222
int __flsl(long x)
int __ffsll(long long x)
int __ffsl(long x)
int __flsll(long long x)
static const uint8_t r[3][4]
MD4 shift amounts.
Definition md4.c:54
uint32_t first
First block in range.
Definition pccrr.h:1
static unsigned int x
Definition pixbuf.h:63