[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/20] host-utils: add ffsl
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 01/20] host-utils: add ffsl |
Date: |
Wed, 12 Dec 2012 14:46:20 +0100 |
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.
Signed-off-by: Paolo Bonzini <address@hidden>
---
host-utils.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/host-utils.h b/host-utils.h
index 821db93..231d580 100644
--- a/host-utils.h
+++ b/host-utils.h
@@ -24,6 +24,7 @@
*/
#include "compiler.h" /* QEMU_GNUC_PREREQ */
+#include <string.h> /* ffsl */
#if defined(__x86_64__)
#define __HAVE_FAST_MULU64__
@@ -234,3 +235,28 @@ static inline int ctpop64(uint64_t val)
return 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
+}
--
1.8.0.1
- Re: [Qemu-devel] [PATCH 14/20] hbitmap: add hbitmap_alloc_with_data and hbitmap_required_size, (continued)
- [Qemu-devel] [PATCH 15/20] hbitmap: add hbitmap_copy, Paolo Bonzini, 2012/12/12
- [Qemu-devel] [PATCH 16/20] block: split bdrv_enable_dirty_tracking and bdrv_disable_dirty_tracking, Paolo Bonzini, 2012/12/12
- [Qemu-devel] [PATCH 18/20] mirror: add support for persistent dirty bitmap, Paolo Bonzini, 2012/12/12
- [Qemu-devel] [PATCH 19/20] block: choose the default dirty bitmap granularity in bdrv_enable_dirty_tracking, Paolo Bonzini, 2012/12/12
- [Qemu-devel] [PATCH 01/20] host-utils: add ffsl,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 17/20] block: support a persistent dirty bitmap, Paolo Bonzini, 2012/12/12
- [Qemu-devel] [PATCH 20/20] monitor: add commands to start/stop dirty bitmap, Paolo Bonzini, 2012/12/12