aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/qemu/bitmap.h7
-rw-r--r--util/bitmap.c32
2 files changed, 39 insertions, 0 deletions
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 2718706edb..509eeddece 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -39,6 +39,8 @@
* bitmap_clear(dst, pos, nbits) Clear specified bit area
* bitmap_test_and_clear_atomic(dst, pos, nbits) Test and clear area
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
+ * bitmap_to_le(dst, src, nbits) Convert bitmap to little endian
+ * bitmap_from_le(dst, src, nbits) Convert bitmap from little endian
*/
/*
@@ -247,4 +249,9 @@ static inline unsigned long *bitmap_zero_extend(unsigned long *old,
return new;
}
+void bitmap_to_le(unsigned long *dst, const unsigned long *src,
+ long nbits);
+void bitmap_from_le(unsigned long *dst, const unsigned long *src,
+ long nbits);
+
#endif /* BITMAP_H */
diff --git a/util/bitmap.c b/util/bitmap.c
index 90a42ff625..cb618c65a5 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -370,3 +370,35 @@ long slow_bitmap_count_one(const unsigned long *bitmap, long nbits)
return result;
}
+
+static void bitmap_to_from_le(unsigned long *dst,
+ const unsigned long *src, long nbits)
+{
+ long len = BITS_TO_LONGS(nbits);
+
+#ifdef HOST_WORDS_BIGENDIAN
+ long index;
+
+ for (index = 0; index < len; index++) {
+# if HOST_LONG_BITS == 64
+ dst[index] = bswap64(src[index]);
+# else
+ dst[index] = bswap32(src[index]);
+# endif
+ }
+#else
+ memcpy(dst, src, len * sizeof(unsigned long));
+#endif
+}
+
+void bitmap_from_le(unsigned long *dst, const unsigned long *src,
+ long nbits)
+{
+ bitmap_to_from_le(dst, src, nbits);
+}
+
+void bitmap_to_le(unsigned long *dst, const unsigned long *src,
+ long nbits)
+{
+ bitmap_to_from_le(dst, src, nbits);
+}