summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-12-04 19:19:45 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-12-04 19:19:45 +0000
commitb39ade83c2eafc231d239c2083b65c84a79bb134 (patch)
tree32932ea5a3d30a4f04580c88f936a91d972aad3f
parent9b3469cc9a0bfb016fd241b7b99c1014e6a64fe5 (diff)
downloadqemu-b39ade83c2eafc231d239c2083b65c84a79bb134.tar.gz
Introduce fls() helper
This is needed for virtio. The implementation is originally from Marcelo Tosatti. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5868 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--cutils.c11
-rw-r--r--qemu-common.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/cutils.c b/cutils.c
index 142347d6ac..9f124f5ea3 100644
--- a/cutils.c
+++ b/cutils.c
@@ -95,3 +95,14 @@ time_t mktimegm(struct tm *tm)
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;
+}
diff --git a/qemu-common.h b/qemu-common.h
index 74eaa4dfc5..308847a21d 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -94,6 +94,7 @@ char *pstrcat(char *buf, int buf_size, const char *s);
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))