]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added more comments / renamed some variables / bm_print() now also works on 64-bit...
authorBart Van Assche <bvanassche@acm.org>
Sat, 22 Mar 2008 17:07:39 +0000 (17:07 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sat, 22 Mar 2008 17:07:39 +0000 (17:07 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7753

exp-drd/drd_bitmap.c
exp-drd/drd_bitmap.h

index 912065b38c660c42fc8229a62987a50d69154287..992e1eae0c76c1c188fc14e1717924c9f888f6d8 100644 (file)
@@ -122,13 +122,16 @@ void bm_access_range(struct bitmap* const bm,
     tl_assert(b_start < b_end);
     tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK));
       
-    for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++)
+    if (access_type == eLoad)
     {
-      if (access_type == eLoad)
+      for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++)
       {
         bm0_set(bm2->bm1.bm0_r, b0);
       }
-      else
+    }
+    else
+    {
+      for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++)
       {
         bm0_set(bm2->bm1.bm0_w, b0);
       }
@@ -708,21 +711,18 @@ void bm_print(const struct bitmap* const bm)
   for ( ; (bm2 = VG_(OSetGen_Next)(bm->oset)) != 0; )
   {
     const struct bitmap1* const bm1 = &bm2->bm1;
-    unsigned k;
-    for (k = 0; k < BITMAP1_UWORD_COUNT; k++)
+    unsigned b;
+    for (b = 0; b < ADDR0_COUNT; b++)
     {
-      unsigned b;
-      for (b = 0; b < BITS_PER_UWORD; b++)
+      const Addr a = (bm2->addr << ADDR0_BITS) | b;
+      const Bool r = bm0_is_set(bm1->bm0_r, b) != 0;
+      const Bool w = bm0_is_set(bm1->bm0_w, b) != 0;
+      if (r || w)
       {
-        int const r = bm1->bm0_r[k] & bm0_mask(b);
-        int const w = bm1->bm0_w[k] & bm0_mask(b);
-        Addr const a = MAKE_ADDRESS(bm2->addr, k * BITS_PER_UWORD | b);
-        if (r || w)
-        {
-          VG_(printf)("0x%08lx %c %c\n",
-                      (Addr)(a), 
-                      w ? 'W' : ' ', r ? 'R' : ' ');
-        }
+        VG_(printf)("0x%08lx %c %c\n",
+                    a,
+                    w ? 'W' : ' ',
+                    r ? 'R' : ' ');
       }
     }
   }
@@ -761,21 +761,21 @@ static void bm2_merge(struct bitmap2* const bm2l,
 static
 struct { Addr address; SizeT size; BmAccessTypeT access_type; }
   s_args[] = {
-    {          0, 1, eLoad  },
-    {        666, 4, eLoad  },
-    {        667, 2, eStore },
-    {       1024, 1, eStore },
-    { 0x0000ffff, 1, eLoad  },
-    { 0x0001ffff, 1, eLoad  },
-    { 0x00ffffff, 1, eLoad  },
-    { 0xffffffff, 1, eStore },
+    {    0 + ADDR0_COUNT, 1, eLoad  },
+    {  666 + ADDR0_COUNT, 4, eLoad  },
+    {  667 + ADDR0_COUNT, 2, eStore },
+    { -1 + 2*ADDR0_COUNT, 1, eStore },
+    {       0x0001ffffUL, 1, eLoad  },
+    {       0x0002ffffUL, 1, eLoad  },
+    {       0x00ffffffUL, 1, eLoad  },
+    {       0xffffffffUL, 1, eStore },
   };
 
 void bm_test(void)
 {
   struct bitmap* bm;
   struct bitmap* bm2;
-  int i, j;
+  unsigned i, j;
 
   VG_(printf)("Start of DRD BM unit test.\n");
 
@@ -801,10 +801,14 @@ void bm_test(void)
   }
 
   VG_(printf)("Merge result:\n");
-  bm2 = bm_merge(bm, bm);
+  bm2 = bm_new();
+  bm_merge2(bm2, bm);
+  bm_merge2(bm2, bm);
   bm_print(bm);
 
+  VG_(printf)("Deleting bitmap bm\n");
   bm_delete(bm);
+  VG_(printf)("Deleting bitmap bm2\n");
   bm_delete(bm2);
 
   VG_(printf)("End of DRD BM unit test.\n");
index 0fbe5a3ccef63e37ab9c87504ec70dbf9d5de2d4..a7d307e94f2cf545452c0429f86493d4842b20ff 100644 (file)
 #define UWORD_HIGHEST_ADDRESS(a) ((a) | (BITS_PER_UWORD - 1))
 
 
-// Local constants.
+/* Local constants. */
 
 static ULong s_bitmap2_creation_count;
 
 
+
+/*********************************************************************/
+/*           Functions for manipulating a struct bitmap1.            */
+/*********************************************************************/
+
+
 /* Lowest level, corresponding to the lowest ADDR0_BITS of an address. */
 struct bitmap1
 {
@@ -139,6 +145,9 @@ static __inline__ UWord bm0_is_any_set(const UWord* bm0,
 }
 
 
+
+/*********************************************************************/
+/*           Functions for manipulating a struct bitmap.             */
 /*********************************************************************/
 
 
@@ -156,6 +165,10 @@ struct bitmap
   OSet*           oset;
 };
 
+/** Look up the address a1 in bitmap bm.
+ *  @param a1 client address shifted right by ADDR0_BITS.
+ *  @param bm bitmap pointer.
+ */
 static __inline__
 struct bitmap2* bm2_lookup(const struct bitmap* const bm, const UWord a1)
 {
@@ -164,7 +177,7 @@ struct bitmap2* bm2_lookup(const struct bitmap* const bm, const UWord a1)
   {
     return bm->last_lookup_result;
   }
-  result = VG_(OSetGen_Lookup)(bm->oset,&a1);
+  result = VG_(OSetGen_Lookup)(bm->oset, &a1);
   if (result)
   {
     ((struct bitmap*)bm)->last_lookup_a1     = a1;
@@ -174,41 +187,45 @@ struct bitmap2* bm2_lookup(const struct bitmap* const bm, const UWord a1)
 }
 
 static __inline__
-struct bitmap2* bm2_insert(const struct bitmap* const bm,
-                           const UWord a1)
+struct bitmap2* bm2_insert(const struct bitmap* const bm, const UWord a1)
 {
-  struct bitmap2* const node = VG_(OSetGen_AllocNode)(bm->oset, sizeof(*node));
-  node->addr = a1;
-  VG_(memset)(&node->bm1, 0, sizeof(node->bm1));
-  VG_(OSetGen_Insert)(bm->oset, node);
+  struct bitmap2* const bm2 = VG_(OSetGen_AllocNode)(bm->oset, sizeof(*bm2));
+  bm2->addr = a1;
+  VG_(memset)(&bm2->bm1, 0, sizeof(bm2->bm1));
+  VG_(OSetGen_Insert)(bm->oset, bm2);
   
   ((struct bitmap*)bm)->last_lookup_a1     = a1;
-  ((struct bitmap*)bm)->last_lookup_result = node;
+  ((struct bitmap*)bm)->last_lookup_result = bm2;
   
   s_bitmap2_creation_count++;
   
-  return node;
+  return bm2;
 }
 
+/** Look up the address a1 in bitmap bm, and insert it if not found.
+ *
+ *  @param a1 client address shifted right by ADDR0_BITS.
+ *  @param bm bitmap pointer.
+ */
 static __inline__
 struct bitmap2* bm2_lookup_or_insert(const struct bitmap* const bm,
                                      const UWord a1)
 {
-  struct bitmap2* p2;
+  struct bitmap2* bm2;
 
   if (a1 == bm->last_lookup_a1)
   {
     return bm->last_lookup_result;
   }
 
-  p2 = VG_(OSetGen_Lookup)(bm->oset, &a1);
-  if (p2 == 0)
+  bm2 = VG_(OSetGen_Lookup)(bm->oset, &a1);
+  if (bm2 == 0)
   {
-    p2 = bm2_insert(bm, a1);
+    bm2 = bm2_insert(bm, a1);
   }
   ((struct bitmap*)bm)->last_lookup_a1     = a1;
-  ((struct bitmap*)bm)->last_lookup_result = p2;
-  return p2;
+  ((struct bitmap*)bm)->last_lookup_result = bm2;
+  return bm2;
 }