All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linda Jacobson <lindaj@jma3.com>
To: xen-devel@lists.xen.org
Cc: wei.liu2@citrix.com, ian.campbell@citrix.com,
	stefano.stabellini@eu.citrix.com, lars.kurth.xen@gmail.com,
	julien.grall@citrix.com, ian.jackson@citrix.com, lindaj@jma3.com
Subject: [PATCH] new functions libxl_bitmap_{or,and}
Date: Mon, 13 Apr 2015 01:47:18 -0600	[thread overview]
Message-ID: <1428911238-6244-1-git-send-email-lindaj@jma3.com> (raw)

provide logical and and or of two bitmaps

---

v.1  updated comments and format
v.2  rewrote bitmap functions to manipulate bytes not bits

Signed-off-by: Linda Jacobson <lindaj@jma3.com>
---
 tools/libxl/libxl_utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h |  5 ++++
 2 files changed, 79 insertions(+)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 9053b27..5c7178f 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -691,6 +691,80 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
     bitmap->map[bit / 8] &= ~(1 << (bit & 7));
 }
 
+/* provide logical or and logical and of two bitmaps */
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    GC_INIT(ctx);
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap;
+    libxl_bitmap *smap;
+
+    if (map1->size > map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {
+        lgmap = map2;
+        smap = map1;
+    }
+
+    rc = libxl_bitmap_alloc(ctx, or_map, lgmap->size * 8);
+    if (rc)
+        goto out;
+
+    /*
+     *  if bitmaps aren't the same size, their union (logical or) will
+     *  be size of larger bit map.  Any bit past the end of the
+     *  smaller bit map, will match the larger one.
+     */
+    for (i = 0; i < smap->size; i++)
+        or_map->map[i] = (smap->map[i] | lgmap->map[i]);
+
+    for (i = smap->size; i < lgmap->size; i++)
+        or_map->map[i] = lgmap->map[i];
+
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    GC_INIT(ctx);    
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap, *smap;
+
+    if (map1->size >  map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {
+        lgmap = map2;
+        smap = map1;
+    }
+
+
+    rc = libxl_bitmap_alloc(ctx, and_map, smap->size * 8);
+    if (rc)
+        goto out;
+
+    /* 
+     *  if bitmaps aren't same size, their 'and' will be size of
+     *  smaller bit map
+     */
+    for (i = 0; i < and_map->size; i++)
+        and_map->map[i] = (lgmap->map[i] & smap->map[i]);
+
+out: 
+    GC_FREE;
+    return rc;
+
+}
+
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
 {
     int i, nr_set_bits = 0;
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index acacdd9..1c0086b 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -90,6 +90,11 @@ int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_set(libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit);
 int libxl_bitmap_count_set(const libxl_bitmap *cpumap);
+/* or and and functions for two bitmaps */
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2); 
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2);
 char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *cpumap);
 static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap)
 {
-- 
1.9.1

             reply	other threads:[~2015-04-13  7:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13  7:47 Linda Jacobson [this message]
2015-04-14  9:19 ` [PATCH] new functions libxl_bitmap_{or,and} Wei Liu
2015-04-14 12:14   ` Linda
2015-04-14 12:28     ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428911238-6244-1-git-send-email-lindaj@jma3.com \
    --to=lindaj@jma3.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=julien.grall@citrix.com \
    --cc=lars.kurth.xen@gmail.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.