Skip to content

Commit

Permalink
Introduce fls() helper
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aliguori committed Dec 4, 2008
1 parent 9b3469c commit b39ade8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions qemu-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b39ade8

Please sign in to comment.