Fixed a bug (wrong constant) in the lowest function causing a wrong path to be taken...
authorphil <none@none>
Mon, 9 Nov 1998 13:35:51 +0000 (13:35 +0000)
committerphil <none@none>
Mon, 9 Nov 1998 13:35:51 +0000 (13:35 +0000)
mm/bitmap2.c
mm/bitmap2.h

index 30527cb6c29bb29ec554e779b4506323ba53469b..9a257e27eedb9ca91cd2d10d7c8c3d8d02aded45 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Authors: Philipp Tomsich     EMAIL: cacao@complang.tuwien.ac.at
  *
- * $Id: bitmap2.c 37 1998-11-04 12:39:19Z phil $
+ * $Id: bitmap2.c 45 1998-11-09 13:35:51Z phil $
  */
 
 /*
  *    if the addr argument is out of range.
  */
 
+/* TODO:
+ *   Rewrite bitmap_find_next_setbit and bitmap_find_next_combination_set_unset 
+ *   to use more pointer arithmetic and less indexed accesses. --phil.
+ *   Reason: Most compilers are simply dumb, while some programmers are not!
+ */
+
 #include <assert.h>  /* assert */
 #include <stdio.h>   /* printf, fprintf */
 #include <stdlib.h>  /* malloc, free */
@@ -136,10 +142,9 @@ void bitmap_boundscheck(bitmap_t* bitmap,
 {
        /* check the lower bound */
        assert((void*)&bitmap->bitmap[ADDR_TO_BLOCK(addr)] >= bitmap->bitmap_memory);
+
        /* check the upper bound */
-       assert(&bitmap->bitmap[
-                                                  ADDR_TO_BLOCK(addr)] 
-                  <= &bitmap->bitmap[bitmap->bitmap_top_block]);
+       assert(&bitmap->bitmap[ADDR_TO_BLOCK(addr)] <= &bitmap->bitmap[bitmap->bitmap_top_block]);
        assert(addr < bitmap->bitmap_beyond_addr); /* a stricter way to check the upper bound */
 }
 
@@ -263,7 +268,7 @@ int offset_for_lowest(BITBLOCK i)
        };
 
 #if U8_AVAILABLE
-       if (i & 0xffffffffffULL)
+       if (i & 0xffffffffULL)
 #endif
                if (i & 0xffffUL)
                        if (i & 0xffUL) 
@@ -329,6 +334,9 @@ bitmap_find_next_combination_set_unset(bitmap_t* bitmap,
        BITBLOCK  pattern;
 
        bitmap_boundscheck(bitmap, addr);
+       bitmap_boundscheck(invertedmap, addr);
+
+       //              fprintf(stderr, "bitmap_find_next_combination_set_unset(0x%lx, 0x%lx. 0x%lx);\n", bitmap, invertedmap, addr);
 
        /* 1. check the current block, starting from the bit indicated by addr */
        pattern = (bitmap->bitmap[block] & ~invertedmap->bitmap[block]) >> offset;
@@ -337,10 +345,16 @@ bitmap_find_next_combination_set_unset(bitmap_t* bitmap,
 
        /* 2. iteratively check block by block until the end of the bitmap */
        while (block < bitmap->bitmap_top_block) {
-               pattern = bitmap->bitmap[++block] & ~invertedmap->bitmap[block];
+               ++block;
+               pattern = bitmap->bitmap[block] & ~invertedmap->bitmap[block];
+
+               if (pattern) {
+                       //                      fprintf(stderr, "\tbitmap->bitmap[block] = 0x%lx, ~invertedmap->bitmap[block] = 0x%lx\n",
+                       //                                      bitmap->bitmap[block], ~invertedmap->bitmap[block]);
+                       //                      fprintf(stderr, "\tpattern = 0x%lx, BLOCK_TO_ADDR(block) = 0x%lx\n", pattern, BLOCK_TO_ADDR(block));
 
-               if (pattern)
                        return (void*)(BLOCK_TO_ADDR(block) + offset_for_lowest(pattern));
+               }
        }
 
        /* 3. failed to find a combination... */
index 4f4b1014984686fa933db18caa7ca720c8e2a038..7505e44bb6bf22fdca0b5e29b8602d60ec8290ab 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * cacao/mm/bitmap.h
- * $Id: bitmap2.h 37 1998-11-04 12:39:19Z phil $ 
+ * $Id: bitmap2.h 45 1998-11-09 13:35:51Z phil $ 
  */
 
 #ifndef __mm_bitmap_h_
@@ -8,8 +8,14 @@
 
 #include "mm.h"
 
+#ifndef CACAO_NO_INLINE
+#define __cacao_inline__  inline
+#else
+#define __cacao_inline__
+#endif
+
 #ifdef __GNUC__
-#define __inline__  inline
+#define __inline__  __cacao_inline__
 #else
 #define __inline__
 #endif