* [Qemu-devel] [5868] Introduce fls() helper
@ 2008-12-04 19:19 Anthony Liguori
0 siblings, 0 replies; only message in thread
From: Anthony Liguori @ 2008-12-04 19:19 UTC (permalink / raw)
To: qemu-devel
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 <aliguori@us.ibm.com>
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))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-12-04 19:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-04 19:19 [Qemu-devel] [5868] Introduce fls() helper Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).