qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [5868] Introduce fls() helper


From: Anthony Liguori
Subject: [Qemu-devel] [5868] Introduce fls() helper
Date: Thu, 04 Dec 2008 19:19:46 +0000

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.

Signed-off-by: Anthony Liguori <address@hidden>

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

Modified: trunk/cutils.c
===================================================================
--- trunk/cutils.c      2008-12-04 18:01:26 UTC (rev 5867)
+++ trunk/cutils.c      2008-12-04 19:19:45 UTC (rev 5868)
@@ -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
===================================================================
--- trunk/qemu-common.h 2008-12-04 18:01:26 UTC (rev 5867)
+++ trunk/qemu-common.h 2008-12-04 19:19:45 UTC (rev 5868)
@@ -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))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]