aboutsummaryrefslogtreecommitdiff
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 /cutils.c
parentClarify -soundhw documentation as to avoid hda confusion (diff)
downloadqemu-kvm-b39ade83c2eafc231d239c2083b65c84a79bb134.tar.gz
qemu-kvm-b39ade83c2eafc231d239c2083b65c84a79bb134.tar.bz2
qemu-kvm-b39ade83c2eafc231d239c2083b65c84a79bb134.zip
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
Diffstat (limited to 'cutils.c')
-rw-r--r--cutils.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/cutils.c b/cutils.c
index 142347d6a..9f124f5ea 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;
+}