]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Minor optimization: eliminated one if statement from each bm_clear*() function.
authorBart Van Assche <bvanassche@acm.org>
Fri, 24 Apr 2009 14:49:50 +0000 (14:49 +0000)
committerBart Van Assche <bvanassche@acm.org>
Fri, 24 Apr 2009 14:49:50 +0000 (14:49 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9609

drd/drd_bitmap.c
drd/drd_bitmap.h

index a70a7e07fb446308ddf765303c703b27ac2c6317..75ad65833a0f1bd192f8dad774cda826213db01a 100644 (file)
@@ -489,38 +489,42 @@ void DRD_(bm_clear)(struct bitmap* const bm, const Addr a1, const Addr a2)
       /* start on an UWord boundary, start clearing the first addresses.  */
       if (UWORD_LSB(c))
       {
-        Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD;
-        if (c_next > b_next)
-           c_next = b_next;
-        bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c);
-        bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c);
-        c = c_next;
+         Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD;
+         if (c_next > b_next)
+            c_next = b_next;
+#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
+         tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next
+                   && b_next <= a2);
+#endif
+         bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c);
+         bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c);
+         c = c_next;
       }
       /* If some UWords have to be cleared entirely, do this now. */
       if (UWORD_LSB(c) == 0)
       {
-        const Addr c_next = UWORD_MSB(b_next);
+         const Addr c_next = UWORD_MSB(b_next);
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
-        tl_assert(UWORD_LSB(c) == 0);
-        tl_assert(UWORD_LSB(c_next) == 0);
-        tl_assert(c_next <= b_next);
-        tl_assert(c <= c_next);
+         tl_assert(UWORD_LSB(c) == 0);
+         tl_assert(UWORD_LSB(c_next) == 0);
+         tl_assert(c_next <= b_next);
+         tl_assert(c <= c_next);
 #endif
-        if (c_next > c)
-        {
-           UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD;
-           VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8);
-           VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8);
-           c = c_next;
-        }
+         if (c_next > c)
+         {
+            UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD;
+            VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8);
+            VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8);
+            c = c_next;
+         }
       }
       /* If the last address in the bitmap that must be cleared does not */
       /* fall on an UWord boundary, clear the last addresses.            */
-      if (c < b_next)
-      {
-         bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c);
-         bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c);
-      }
+#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
+      tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2);
+#endif
+      bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c);
+      bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c);
    }
 }
 
@@ -570,15 +574,15 @@ void DRD_(bm_clear_load)(struct bitmap* const bm, const Addr a1, const Addr a2)
 #endif
       if (UWORD_LSB(c))
       {
-        Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD;
-        if (c_next > b_next)
-           c_next = b_next;
+         Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD;
+         if (c_next > b_next)
+            c_next = b_next;
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
-        tl_assert(a1 <= b && b <= c && c < c_next && c_next <= b_next
-                  && b_next <= a2);
+         tl_assert(a1 <= b && b <= c && c < c_next && c_next <= b_next
+                   && b_next <= a2);
 #endif
-        bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c);
-        c = c_next;
+         bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c);
+         c = c_next;
       }
       /* If some UWords have to be cleared entirely, do this now. */
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
@@ -586,29 +590,26 @@ void DRD_(bm_clear_load)(struct bitmap* const bm, const Addr a1, const Addr a2)
 #endif
       if (UWORD_LSB(c) == 0)
       {
-        const Addr c_next = UWORD_MSB(b_next);
+         const Addr c_next = UWORD_MSB(b_next);
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
-        tl_assert(UWORD_LSB(c) == 0);
-        tl_assert(UWORD_LSB(c_next) == 0);
-        tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next
-                  && b_next <= a2);
+         tl_assert(UWORD_LSB(c) == 0);
+         tl_assert(UWORD_LSB(c_next) == 0);
+         tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next
+                   && b_next <= a2);
 #endif
-        if (c_next > c)
-        {
-           UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD;
-           VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8);
-           c = c_next;
-        }
+         if (c_next > c)
+         {
+            UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD;
+            VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8);
+            c = c_next;
+         }
       }
       /* If the last address in the bitmap that must be cleared does not */
       /* fall on an UWord boundary, clear the last addresses.            */
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
       tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2);
 #endif
-      if (c < b_next)
-      {
-        bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c);
-      }
+      bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c);
    }
 }
 
@@ -645,7 +646,7 @@ void DRD_(bm_clear_store)(struct bitmap* const bm,
       b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT;
       if (b_next > a2)
       {
-       b_next = a2;
+        b_next = a2;
       }
 
       if (p2 == 0)
@@ -659,15 +660,15 @@ void DRD_(bm_clear_store)(struct bitmap* const bm,
 #endif
       if (UWORD_LSB(c))
       {
-       Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD;
-       if (c_next > b_next)
-         c_next = b_next;
+        Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD;
+        if (c_next > b_next)
+          c_next = b_next;
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
-       tl_assert(a1 <= b && b <= c && c < c_next && c_next <= b_next
-                 && b_next <= a2);
+        tl_assert(a1 <= b && b <= c && c < c_next && c_next <= b_next
+                  && b_next <= a2);
 #endif
-       bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c);
-       c = c_next;
+        bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c);
+        c = c_next;
       }
       /* If some UWords have to be cleared entirely, do this now. */
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
@@ -675,29 +676,26 @@ void DRD_(bm_clear_store)(struct bitmap* const bm,
 #endif
       if (UWORD_LSB(c) == 0)
       {
-       const Addr c_next = UWORD_MSB(b_next);
+        const Addr c_next = UWORD_MSB(b_next);
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
-       tl_assert(UWORD_LSB(c) == 0);
-       tl_assert(UWORD_LSB(c_next) == 0);
-       tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next
-                 && b_next <= a2);
+        tl_assert(UWORD_LSB(c) == 0);
+        tl_assert(UWORD_LSB(c_next) == 0);
+        tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next
+                  && b_next <= a2);
 #endif
-       if (c_next > c)
-       {
-         UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD;
-         VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8);
-         c = c_next;
-       }
+        if (c_next > c)
+        {
+           UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD;
+           VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8);
+           c = c_next;
+        }
       }
       /* If the last address in the bitmap that must be cleared does not */
       /* fall on an UWord boundary, clear the last addresses.            */
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
       tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2);
 #endif
-      if (c < b_next)
-      {
-       bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c);
-      }
+      bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c);
    }
 }
 
index 1689435df4e80c049f3a6bf77513fc6617a99b71..0043cdcad4a9a77c780e084373a66cb286a99b25 100644 (file)
@@ -137,9 +137,9 @@ static __inline__ void bm0_clear_range(UWord* bm0,
 {
 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
    tl_assert(a1 < ADDR0_COUNT);
-   tl_assert(size > 0);
+   tl_assert(size >= 0);
    tl_assert(a1 + size <= ADDR0_COUNT);
-   tl_assert(UWORD_MSB(a1) == UWORD_MSB(a1 + size - 1));
+   tl_assert(size == 0 || UWORD_MSB(a1) == UWORD_MSB(a1 + size - 1));
 #endif
    bm0[a1 >> BITS_PER_BITS_PER_UWORD]
       &= ~((((UWord)1 << size) - 1) << UWORD_LSB(a1));