]> Git Repo - qemu.git/blobdiff - include/qemu/hbitmap.h
machine: Eliminate QEMUMachine and qemu_register_machine()
[qemu.git] / include / qemu / hbitmap.h
index 7ddfb6680809903b989d549647c1e6238c595877..bb94a00c5f4381a1b192a2f242887f289117609a 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "bitops.h"
+#include "host-utils.h"
 
 typedef struct HBitmap HBitmap;
 typedef struct HBitmapIter HBitmapIter;
@@ -63,6 +64,29 @@ struct HBitmapIter {
  */
 HBitmap *hbitmap_alloc(uint64_t size, int granularity);
 
+/**
+ * hbitmap_truncate:
+ * @hb: The bitmap to change the size of.
+ * @size: The number of elements to change the bitmap to accommodate.
+ *
+ * truncate or grow an existing bitmap to accommodate a new number of elements.
+ * This may invalidate existing HBitmapIterators.
+ */
+void hbitmap_truncate(HBitmap *hb, uint64_t size);
+
+/**
+ * hbitmap_merge:
+ * @a: The bitmap to store the result in.
+ * @b: The bitmap to merge into @a.
+ * @return true if the merge was successful,
+ *         false if it was not attempted.
+ *
+ * Merge two bitmaps together.
+ * A := A (BITOR) B.
+ * B is left unmodified.
+ */
+bool hbitmap_merge(HBitmap *a, const HBitmap *b);
+
 /**
  * hbitmap_empty:
  * @hb: HBitmap to operate on.
@@ -107,6 +131,14 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count);
  */
 void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count);
 
+/**
+ * hbitmap_reset_all:
+ * @hb: HBitmap to operate on.
+ *
+ * Reset all bits in an HBitmap.
+ */
+void hbitmap_reset_all(HBitmap *hb);
+
 /**
  * hbitmap_get:
  * @hb: HBitmap to operate on.
@@ -128,7 +160,8 @@ void hbitmap_free(HBitmap *hb);
  * hbitmap_iter_init:
  * @hbi: HBitmapIter to initialize.
  * @hb: HBitmap to iterate on.
- * @first: First bit to visit (0-based).
+ * @first: First bit to visit (0-based, must be strictly less than the
+ * size of the bitmap).
  *
  * Set up @hbi to iterate on the HBitmap @hb.  hbitmap_iter_next will return
  * the lowest-numbered bit that is set in @hb, starting at @first.
@@ -169,7 +202,7 @@ static inline int64_t hbitmap_iter_next(HBitmapIter *hbi)
 
     /* The next call will resume work from the next bit.  */
     hbi->cur[HBITMAP_LEVELS - 1] = cur & (cur - 1);
-    item = ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ffsl(cur) - 1;
+    item = ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur);
 
     return item << hbi->granularity;
 }
This page took 0.024695 seconds and 4 git commands to generate.