Skip to contentSkip to conversation

[5868] Introduce fls() helper

Qemu-devel Anthony Liguori 1 participant 1 message Dec 4, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5868

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5868
Author:   aliguori
Date:     2008-12-04 19:19:45 +0000 (Thu, 04 Dec 2008)

Log Message:
-----------
Introduce fls() helper

This is needed for virtio. The implementation is originally from Marcelo Tosatti.

Modified Paths:
--------------
trunk/cutils.c
trunk/qemu-common.h

Modified: trunk/cutils.c
===================================================================

cutils.c +11 -0
@@ -95,3 +95,14 @@
     t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
     return t;
 }
+
+int fls(int i)
+{
+    int bit;
+
+    for (bit=31; bit >= 0; bit--)
+        if (i & (1 << bit))
+            return bit+1;
+
+    return 0;
+}

Modified: trunk/qemu-common.h
===================================================================

qemu-common.h +1 -0
@@ -94,6 +94,7 @@
 int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
 time_t mktimegm(struct tm *tm);
+int fls(int i);
 
 #define qemu_isalnum(c)		isalnum((unsigned char)(c))
 #define qemu_isalpha(c)		isalpha((unsigned char)(c))