提交 4c37ef02 编写于 作者: P Paolo Bonzini 提交者: Kevin Wolf

host-utils: add ffsl

We can provide fast versions based on the other functions defined
by host-utils.h.  Some care is required on glibc, which provides
ffsl already.
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 11c29918
......@@ -26,6 +26,7 @@
#define HOST_UTILS_H 1
#include "qemu/compiler.h" /* QEMU_GNUC_PREREQ */
#include <string.h> /* ffsl */
#if defined(__x86_64__)
#define __HAVE_FAST_MULU64__
......@@ -237,4 +238,29 @@ static inline int ctpop64(uint64_t val)
#endif
}
/* glibc does not provide an inline version of ffsl, so always define
* ours. We need to give it a different name, however.
*/
#ifdef __GLIBC__
#define ffsl qemu_ffsl
#endif
static inline int ffsl(long val)
{
if (!val) {
return 0;
}
#if QEMU_GNUC_PREREQ(3, 4)
return __builtin_ctzl(val) + 1;
#else
if (sizeof(long) == 4) {
return ctz32(val) + 1;
} else if (sizeof(long) == 8) {
return ctz64(val) + 1;
} else {
abort();
}
#endif
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册