Browse Source

Add fls() for non-constant values.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
db124b1255
2 changed files with 11 additions and 5 deletions
  1. 10
    0
      src/core/bitops.c
  2. 1
    5
      src/include/strings.h

+ 10
- 0
src/core/bitops.c View File

@@ -0,0 +1,10 @@
1
+#include <strings.h>
2
+
3
+int __flsl ( long x ) {
4
+	int r = 0;
5
+
6
+	for ( r = 0 ; x ; r++ ) {
7
+		x >>= 1;
8
+	}
9
+	return r;
10
+}

+ 1
- 5
src/include/strings.h View File

@@ -40,17 +40,13 @@ __constant_flsl ( unsigned long x ) {
40 40
 	return r;
41 41
 }
42 42
 
43
-#define __constant_fls(x) __constant_flsl(x)
44
-
45 43
 /* We don't actually have these functions yet */
46
-extern int __fls ( int x );
47 44
 extern int __flsl ( long x );
48 45
 
49 46
 #define flsl( x ) \
50 47
 	( __builtin_constant_p ( x ) ? __constant_flsl ( x ) : __flsl ( x ) )
51 48
 
52
-#define fls( x ) \
53
-	( __builtin_constant_p ( x ) ? __constant_fls ( x ) : __fls ( x ) )
49
+#define fls( x ) flsl ( x )
54 50
 
55 51
 extern int strcasecmp ( const char *s1, const char *s2 );
56 52
 

Loading…
Cancel
Save