[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/24] host-utils: add ffsl
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 01/24] host-utils: add ffsl |
Date: |
Fri, 25 Jan 2013 19:45:37 +0100 |
From: Paolo Bonzini <address@hidden>
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: Eric Blake <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/qemu/host-utils.h | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 81c9a75..2a32be4 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -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
--
1.7.6.5
- [Qemu-devel] [PULL 00/24] Block patches, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 01/24] host-utils: add ffsl,
Kevin Wolf <=
- [Qemu-devel] [PATCH 03/24] block: implement dirty bitmap using HBitmap, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 02/24] add hierarchical bitmap data type and test cases, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 05/24] mirror: perform COW if the cluster size is bigger than the granularity, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 04/24] block: make round_to_clusters public, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 07/24] block: allow customizing the granularity of the dirty bitmap, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 06/24] block: return count of dirty sectors, not chunks, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 09/24] mirror: switch mirror_iteration to AIO, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 08/24] mirror: allow customizing the granularity, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 10/24] mirror: add buf-size argument to drive-mirror, Kevin Wolf, 2013/01/25
- [Qemu-devel] [PATCH 11/24] mirror: support more than one in-flight AIO operation, Kevin Wolf, 2013/01/25