From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 1/3] QEMU/KVM: add fls() Date: Mon, 17 Mar 2008 17:20:14 -0300 Message-ID: <20080317202125.325812182@localhost.localdomain> References: <20080317202013.949027343@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel , Marcelo Tosatti To: Avi Kivity Return-path: Content-Disposition: inline; filename=add-fls List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org Find Last Set, in accordance with glibc's ffs. Signed-off-by: Marcelo Tosatti Index: kvm-userspace.hotplug3/qemu/cutils.c =================================================================== --- kvm-userspace.hotplug3.orig/qemu/cutils.c +++ kvm-userspace.hotplug3/qemu/cutils.c @@ -135,3 +135,14 @@ char *urldecode(const char *ptr) return ret; } +int fls(int i) +{ + int bit; + + for (bit=31; bit >= 0; bit--) + if (i & (1 << bit)) + return bit+1; + + return 0; +} + Index: kvm-userspace.hotplug3/qemu/qemu-common.h =================================================================== --- kvm-userspace.hotplug3.orig/qemu/qemu-common.h +++ kvm-userspace.hotplug3/qemu/qemu-common.h @@ -87,6 +87,7 @@ int stristart(const char *str, const cha time_t mktimegm(struct tm *tm); int hex2bin(char ch); char *urldecode(const char *ptr); +int fls(int i); /* Error handling. */ -- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/