Commit b39ade83c2eafc231d239c2083b65c84a79bb134

Authored by aliguori
1 parent 9b3469cc

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
Showing 2 changed files with 12 additions and 0 deletions
cutils.c
... ... @@ -95,3 +95,14 @@ time_t mktimegm(struct tm *tm)
95 95 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
96 96 return t;
97 97 }
  98 +
  99 +int fls(int i)
  100 +{
  101 + int bit;
  102 +
  103 + for (bit=31; bit >= 0; bit--)
  104 + if (i & (1 << bit))
  105 + return bit+1;
  106 +
  107 + return 0;
  108 +}
... ...
qemu-common.h
... ... @@ -94,6 +94,7 @@ char *pstrcat(char *buf, int buf_size, const char *s);
94 94 int strstart(const char *str, const char *val, const char **ptr);
95 95 int stristart(const char *str, const char *val, const char **ptr);
96 96 time_t mktimegm(struct tm *tm);
  97 +int fls(int i);
97 98  
98 99 #define qemu_isalnum(c) isalnum((unsigned char)(c))
99 100 #define qemu_isalpha(c) isalpha((unsigned char)(c))
... ...