Skip to contentSkip to conversation

[5872] Define fls() in terms of clz32().

Qemu-devel Anthony Liguori 1 participant 1 message Dec 4, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5872

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5872
Author:   aliguori
Date:     2008-12-04 20:08:06 +0000 (Thu, 04 Dec 2008)

Log Message:
-----------
Define fls() in terms of clz32().

As suggested by Laurent Desnogues.

Modified Paths:
--------------
trunk/cutils.c

Modified: trunk/cutils.c
===================================================================

cutils.c +2 -7
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
+#include "host-utils.h"
 
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
@@ -98,11 +99,5 @@
 
 int fls(int i)
 {
-    int bit;
-
-    for (bit=31; bit >= 0; bit--)
-        if (i & (1 << bit))
-            return bit+1;
-
-    return 0;
+    return 32 - clz32(i);
 }