All of lore.kernel.org
 help / color / mirror / Atom feed
* [[PATCH v4]] new functions libxl_bitmap_{or,and}
@ 2015-04-14 14:07 Linda Jacobson
  2015-04-14 16:33 ` Wei Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Linda Jacobson @ 2015-04-14 14:07 UTC (permalink / raw)
  To: xen-devel
  Cc: wei.liu2, ian.campbell, stefano.stabellini, lars.kurth.xen,
	julien.grall, ian.jackson, lindaj

provide logical and and or of two bitmaps

Signed-off-by: Linda Jacobson <lindaj@jma3.com>

---

v.1 new functions
v.2 updated comments and format
v.3 rewrote bitmap functions to manipulate bytes not bits
v.4 made non-modified parameters, and local variables const; fixed code
    formatting
---
 tools/libxl/libxl_utils.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h |  7 +++++
 2 files changed, 80 insertions(+)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 9053b27..2241da9 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -691,6 +691,79 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
     bitmap->map[bit / 8] &= ~(1 << (bit & 7));
 }
 
+
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    const libxl_bitmap *map1, const libxl_bitmap *map2)
+{
+    GC_INIT(ctx);
+    int rc;
+    uint32_t i;
+    const libxl_bitmap *large_map;
+    const libxl_bitmap *small_map;
+
+    if (map1->size > map2->size) {
+        large_map = map1;
+        small_map = map2;
+    } else {
+        large_map = map2;
+        small_map = map1;
+    }
+
+    rc = libxl_bitmap_alloc(ctx, or_map, large_map->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 < small_map->size; i++)
+        or_map->map[i] = (small_map->map[i] | large_map->map[i]);
+
+    for (i = small_map->size; i < large_map->size; i++)
+        or_map->map[i] = large_map->map[i];
+
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     const libxl_bitmap *map1, const libxl_bitmap *map2)
+{
+    GC_INIT(ctx);    
+    int rc;
+    uint32_t i;
+    const libxl_bitmap *large_map;
+    const libxl_bitmap *small_map;
+
+    if (map1->size > map2->size) {
+        large_map = map1;
+        small_map = map2;
+    } else {
+        large_map = map2;
+        small_map = map1;
+    }
+
+
+    rc = libxl_bitmap_alloc(ctx, and_map, small_map->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] = (large_map->map[i] & small_map->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..a128a7c 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -90,6 +90,13 @@ 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,
+                    const libxl_bitmap *map1, 
+                    const libxl_bitmap *map2); 
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     const libxl_bitmap *map1, 
+                     const 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [[PATCH v4]] new functions libxl_bitmap_{or,and}
  2015-04-14 14:07 [[PATCH v4]] new functions libxl_bitmap_{or,and} Linda Jacobson
@ 2015-04-14 16:33 ` Wei Liu
  2015-04-14 16:48   ` Linda Jacobson
  2015-04-15 11:07   ` Linda
  0 siblings, 2 replies; 4+ messages in thread
From: Wei Liu @ 2015-04-14 16:33 UTC (permalink / raw)
  To: Linda Jacobson
  Cc: wei.liu2, ian.campbell, stefano.stabellini, lars.kurth.xen,
	xen-devel, julien.grall, ian.jackson

Urgh... I think I made a mistake in the rune I gave you, sorry. The
--subject-prefix= doesn't need to include "[]".

And you forgot to change the subject line to
  libxl: provide libxl_bitmap_{and,or}

I'm a picky about the subject line because this is what shows up when
you look at git commit log.

On Tue, Apr 14, 2015 at 08:07:59AM -0600, Linda Jacobson wrote:
> provide logical and and or of two bitmaps

Provide logical and and or of two bitmaps.

This should be a proper sentence.

Other than these minor nits the code logic looks OK.

> 
> Signed-off-by: Linda Jacobson <lindaj@jma3.com>
> 
> ---
> 
[...]
> +int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
> +                     const libxl_bitmap *map1, const libxl_bitmap *map2)
> +{
> +    GC_INIT(ctx);    
> +    int rc;
> +    uint32_t i;
> +    const libxl_bitmap *large_map;
> +    const libxl_bitmap *small_map;
> +
> +    if (map1->size > map2->size) {
> +        large_map = map1;
> +        small_map = map2;
> +    } else {
> +        large_map = map2;
> +        small_map = map1;
> +    }
> +
> +

We only need one blank line here.

> +    rc = libxl_bitmap_alloc(ctx, and_map, small_map->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] = (large_map->map[i] & small_map->map[i]);
> +
> +out: 
> +    GC_FREE;
> +    return rc;
> +

No need to have blank lines after "return rc;"

Wei.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [[PATCH v4]] new functions libxl_bitmap_{or,and}
  2015-04-14 16:33 ` Wei Liu
@ 2015-04-14 16:48   ` Linda Jacobson
  2015-04-15 11:07   ` Linda
  1 sibling, 0 replies; 4+ messages in thread
From: Linda Jacobson @ 2015-04-14 16:48 UTC (permalink / raw)
  Cc: <wei.liu2@citrix.com>, <ian.campbell@citrix.com>,
	<stefano.stabellini@eu.citrix.com>,
	<lars.kurth.xen@gmail.com>, <xen-devel@lists.xen.org>,
	<julien.grall@citrix.com>, <ian.jackson@citrix.com>

I'll fix it when I get home.  It'll be late where you are.   L

Sent from my iPhone

> On Apr 14, 2015, at 10:33 AM, Wei Liu <wei.liu2@citrix.com> wrote:
> 
> Urgh... I think I made a mistake in the rune I gave you, sorry. The
> --subject-prefix= doesn't need to include "[]".
> 
> And you forgot to change the subject line to
>  libxl: provide libxl_bitmap_{and,or}
> 
> I'm a picky about the subject line because this is what shows up when
> you look at git commit log.
> 
>> On Tue, Apr 14, 2015 at 08:07:59AM -0600, Linda Jacobson wrote:
>> provide logical and and or of two bitmaps
> 
> Provide logical and and or of two bitmaps.
> 
> This should be a proper sentence.
> 
> Other than these minor nits the code logic looks OK.
> 
>> 
>> Signed-off-by: Linda Jacobson <lindaj@jma3.com>
>> 
>> ---
> [...]
>> +int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
>> +                     const libxl_bitmap *map1, const libxl_bitmap *map2)
>> +{
>> +    GC_INIT(ctx);    
>> +    int rc;
>> +    uint32_t i;
>> +    const libxl_bitmap *large_map;
>> +    const libxl_bitmap *small_map;
>> +
>> +    if (map1->size > map2->size) {
>> +        large_map = map1;
>> +        small_map = map2;
>> +    } else {
>> +        large_map = map2;
>> +        small_map = map1;
>> +    }
>> +
>> +
> 
> We only need one blank line here.
> 
>> +    rc = libxl_bitmap_alloc(ctx, and_map, small_map->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] = (large_map->map[i] & small_map->map[i]);
>> +
>> +out: 
>> +    GC_FREE;
>> +    return rc;
>> +
> 
> No need to have blank lines after "return rc;"
> 
> Wei.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [[PATCH v4]] new functions libxl_bitmap_{or,and}
  2015-04-14 16:33 ` Wei Liu
  2015-04-14 16:48   ` Linda Jacobson
@ 2015-04-15 11:07   ` Linda
  1 sibling, 0 replies; 4+ messages in thread
From: Linda @ 2015-04-15 11:07 UTC (permalink / raw)
  To: Wei Liu
  Cc: ian.campbell, stefano.stabellini, lars.kurth.xen, xen-devel,
	julien.grall, ian.jackson

Not ignored.  Sorry.  I shouldn't have read from my iPhone.  I didn't 
see the others.  I'll take care of them.

Linda


On 4/14/2015 10:33 AM, Wei Liu wrote:
> Urgh... I think I made a mistake in the rune I gave you, sorry. The
> --subject-prefix= doesn't need to include "[]".
>
> And you forgot to change the subject line to
>    libxl: provide libxl_bitmap_{and,or}
>
> I'm a picky about the subject line because this is what shows up when
> you look at git commit log.
>
> On Tue, Apr 14, 2015 at 08:07:59AM -0600, Linda Jacobson wrote:
>> provide logical and and or of two bitmaps
> Provide logical and and or of two bitmaps.
>
> This should be a proper sentence.
>
> Other than these minor nits the code logic looks OK.
>
>> Signed-off-by: Linda Jacobson <lindaj@jma3.com>
>>
>> ---
>>
> [...]
>> +int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
>> +                     const libxl_bitmap *map1, const libxl_bitmap *map2)
>> +{
>> +    GC_INIT(ctx);
>> +    int rc;
>> +    uint32_t i;
>> +    const libxl_bitmap *large_map;
>> +    const libxl_bitmap *small_map;
>> +
>> +    if (map1->size > map2->size) {
>> +        large_map = map1;
>> +        small_map = map2;
>> +    } else {
>> +        large_map = map2;
>> +        small_map = map1;
>> +    }
>> +
>> +
> We only need one blank line here.
>
>> +    rc = libxl_bitmap_alloc(ctx, and_map, small_map->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] = (large_map->map[i] & small_map->map[i]);
>> +
>> +out:
>> +    GC_FREE;
>> +    return rc;
>> +
> No need to have blank lines after "return rc;"
>
> Wei.
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-15 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-14 14:07 [[PATCH v4]] new functions libxl_bitmap_{or,and} Linda Jacobson
2015-04-14 16:33 ` Wei Liu
2015-04-14 16:48   ` Linda Jacobson
2015-04-15 11:07   ` Linda

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.