From db124b12551f91a2437014fb74a122ff0d0db08b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 16 Sep 2007 17:36:40 +0100 Subject: [PATCH] Add fls() for non-constant values. --- src/core/bitops.c | 10 ++++++++++ src/include/strings.h | 6 +----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/core/bitops.c diff --git a/src/core/bitops.c b/src/core/bitops.c new file mode 100644 index 00000000..75d57bf9 --- /dev/null +++ b/src/core/bitops.c @@ -0,0 +1,10 @@ +#include + +int __flsl ( long x ) { + int r = 0; + + for ( r = 0 ; x ; r++ ) { + x >>= 1; + } + return r; +} diff --git a/src/include/strings.h b/src/include/strings.h index a087b1d5..968a7c11 100644 --- a/src/include/strings.h +++ b/src/include/strings.h @@ -40,17 +40,13 @@ __constant_flsl ( unsigned long x ) { return r; } -#define __constant_fls(x) __constant_flsl(x) - /* We don't actually have these functions yet */ -extern int __fls ( int x ); extern int __flsl ( long x ); #define flsl( x ) \ ( __builtin_constant_p ( x ) ? __constant_flsl ( x ) : __flsl ( x ) ) -#define fls( x ) \ - ( __builtin_constant_p ( x ) ? __constant_fls ( x ) : __fls ( x ) ) +#define fls( x ) flsl ( x ) extern int strcasecmp ( const char *s1, const char *s2 );