Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L8Jjo-0006WF-Uu for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:19:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L8Jjo-0006Vw-8Y for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:19:48 -0500 Received: from [199.232.76.173] (port=60970 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L8Jjn-0006Vs-TJ for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:19:47 -0500 Received: from savannah.gnu.org ([199.232.41.3]:35563 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L8Jjn-0003hj-DE for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:19:47 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1L8Jjm-0005Lo-SD for qemu-devel@nongnu.org; Thu, 04 Dec 2008 19:19:46 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1L8Jjm-0005Lj-Hq for qemu-devel@nongnu.org; Thu, 04 Dec 2008 19:19:46 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 04 Dec 2008 19:19:46 +0000 Subject: [Qemu-devel] [5868] Introduce fls() helper Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 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))