diff options
author | José Pekkarinen <jose.pekkarinen@nokia.com> | 2016-05-18 13:18:31 +0300 |
---|---|---|
committer | José Pekkarinen <jose.pekkarinen@nokia.com> | 2016-05-18 13:42:15 +0300 |
commit | 437fd90c0250dee670290f9b714253671a990160 (patch) | |
tree | b871786c360704244a07411c69fb58da9ead4a06 /qemu/roms/ipxe/src/include/strings.h | |
parent | 5bbd6fe9b8bab2a93e548c5a53b032d1939eec05 (diff) |
These changes are the raw update to qemu-2.6.
Collission happened in the following patches:
migration: do cleanup operation after completion(738df5b9)
Bug fix.(1750c932f86)
kvmclock: add a new function to update env->tsc.(b52baab2)
The code provided by the patches was already in the upstreamed
version.
Change-Id: I3cc11841a6a76ae20887b2e245710199e1ea7f9a
Signed-off-by: José Pekkarinen <jose.pekkarinen@nokia.com>
Diffstat (limited to 'qemu/roms/ipxe/src/include/strings.h')
-rw-r--r-- | qemu/roms/ipxe/src/include/strings.h | 145 |
1 files changed, 133 insertions, 12 deletions
diff --git a/qemu/roms/ipxe/src/include/strings.h b/qemu/roms/ipxe/src/include/strings.h index 6912a1e45..fab26dc28 100644 --- a/qemu/roms/ipxe/src/include/strings.h +++ b/qemu/roms/ipxe/src/include/strings.h @@ -1,12 +1,71 @@ #ifndef _STRINGS_H #define _STRINGS_H -FILE_LICENCE ( GPL2_OR_LATER ); +/** @file + * + * String functions + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -#include <limits.h> #include <string.h> #include <bits/strings.h> +/** + * Find first (i.e. least significant) set bit + * + * @v x Value + * @ret lsb Least significant bit set in value (LSB=1), or zero + */ +static inline __attribute__ (( always_inline )) int +__constant_ffsll ( unsigned long long x ) { + int r = 0; + + if ( ! ( x & 0x00000000ffffffffULL ) ) { + x >>= 32; + r += 32; + } + if ( ! ( x & 0x0000ffffUL ) ) { + x >>= 16; + r += 16; + } + if ( ! ( x & 0x00ff ) ) { + x >>= 8; + r += 8; + } + if ( ! ( x & 0x0f ) ) { + x >>= 4; + r += 4; + } + if ( ! ( x & 0x3 ) ) { + x >>= 2; + r += 2; + } + if ( ! ( x & 0x1 ) ) { + x >>= 1; + r += 1; + } + return ( x ? ( r + 1 ) : 0 ); +} + +/** + * Find first (i.e. least significant) set bit + * + * @v x Value + * @ret lsb Least significant bit set in value (LSB=1), or zero + */ +static inline __attribute__ (( always_inline )) int +__constant_ffsl ( unsigned long x ) { + return __constant_ffsll ( x ); +} + +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ static inline __attribute__ (( always_inline )) int __constant_flsll ( unsigned long long x ) { int r = 0; @@ -35,38 +94,100 @@ __constant_flsll ( unsigned long long x ) { x >>= 1; r += 1; } - if ( x & 0x1 ) { - r += 1; - } - return r; + return ( x ? ( r + 1 ) : 0 ); } +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ static inline __attribute__ (( always_inline )) int __constant_flsl ( unsigned long x ) { return __constant_flsll ( x ); } +int __ffsll ( long long x ); +int __ffsl ( long x ); int __flsll ( long long x ); int __flsl ( long x ); +/** + * Find first (i.e. least significant) set bit + * + * @v x Value + * @ret lsb Least significant bit set in value (LSB=1), or zero + */ +#define ffsll( x ) \ + ( __builtin_constant_p ( x ) ? __constant_ffsll ( x ) : __ffsll ( x ) ) + +/** + * Find first (i.e. least significant) set bit + * + * @v x Value + * @ret lsb Least significant bit set in value (LSB=1), or zero + */ +#define ffsl( x ) \ + ( __builtin_constant_p ( x ) ? __constant_ffsl ( x ) : __ffsl ( x ) ) + +/** + * Find first (i.e. least significant) set bit + * + * @v x Value + * @ret lsb Least significant bit set in value (LSB=1), or zero + */ +#define ffs( x ) ffsl ( x ) + +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ #define flsll( x ) \ ( __builtin_constant_p ( x ) ? __constant_flsll ( x ) : __flsll ( x ) ) +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ #define flsl( x ) \ ( __builtin_constant_p ( x ) ? __constant_flsl ( x ) : __flsl ( x ) ) +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ #define fls( x ) flsl ( x ) -extern int strcasecmp ( const char *s1, const char *s2 ); - +/** + * Copy memory + * + * @v src Source + * @v dest Destination + * @v len Length + */ static inline __attribute__ (( always_inline )) void -bcopy ( const void *src, void *dest, size_t n ) { - memmove ( dest, src, n ); +bcopy ( const void *src, void *dest, size_t len ) { + memmove ( dest, src, len ); } +/** + * Zero memory + * + * @v dest Destination + * @v len Length + */ static inline __attribute__ (( always_inline )) void -bzero ( void *s, size_t n ) { - memset ( s, 0, n ); +bzero ( void *dest, size_t len ) { + memset ( dest, 0, len ); } +int __pure strcasecmp ( const char *first, const char *second ) __nonnull; + #endif /* _STRINGS_H */ |