Added is_Const
[libfirm] / ir / adt / bitset.h
index 0a7ad4b..1f62168 100644 (file)
@@ -233,11 +233,15 @@ static INLINE unsigned long _bitset_next(const bitset_t *bs,
                 * Mask out the bits smaller than pos in the current unit.
                 * We are only interested in bits set higher than pos.
                 */
-               unsigned long curr_unit = bs->data[unit_number] & ~in_unit_mask;
+               unsigned long curr_unit = bs->data[unit_number];
 
-               /* Find the next bit set in the unit. */
-               unsigned long next_in_this_unit
-                       = _bitset_inside_ntz_value(set ? curr_unit : ~curr_unit);
+               /*
+                * Find the next bit set in the unit.
+                * Mind that this function returns 0, if the unit is -1 and
+                * counts the bits from 1 on.
+                */
+               unsigned long next_in_this_unit =
+                       _bitset_inside_ntz_value((set ? curr_unit : ~curr_unit) & ~in_unit_mask);
 
                /* If there is a bit set in the current unit, exit. */
                if(next_in_this_unit < BS_UNIT_SIZE_BITS)
@@ -248,7 +252,9 @@ static INLINE unsigned long _bitset_next(const bitset_t *bs,
                        unsigned long i;
                        for(i = unit_number + 1; i < bs->units; ++i) {
                                unsigned long data = bs->data[i];
-                               unsigned long first_set = _bitset_inside_ntz_value(set ? data : ~data);
+                               unsigned long first_set =
+                                       _bitset_inside_ntz_value(set ? data : ~data);
+
                                if(first_set < BS_UNIT_SIZE_BITS)
                                        return first_set + i * BS_UNIT_SIZE_BITS;
                        }
@@ -269,6 +275,10 @@ static INLINE unsigned long _bitset_next(const bitset_t *bs,
 #define bitset_foreach(bitset,elm) \
   for(elm = bitset_next_set(bitset,0); elm != -1; elm = bitset_next_set(bitset,elm+1))
 
+
+#define bitset_foreach_clear(bitset,elm) \
+  for(elm = bitset_next_clear(bitset,0); elm != -1; elm = bitset_next_clear(bitset,elm+1))
+
 /**
  * Count the bits set.
  * This can also be seen as the cardinality of the set.
@@ -351,9 +361,9 @@ static INLINE void bitset_fprint(FILE *file, const bitset_t *bs)
 
 static INLINE void bitset_debug_fprint(FILE *file, const bitset_t *bs)
 {
-       int i;
+       unsigned long i;
 
-       fprintf(file, "%d:", bs->units);
+       fprintf(file, "%lu:", bs->units);
        for(i = 0; i < bs->units; ++i)
                fprintf(file, " %0lx", bs->data[i]);
 }
@@ -365,8 +375,8 @@ static INLINE void bitset_debug_fprint(FILE *file, const bitset_t *bs)
 #define BINARY_OP(op) \
 static INLINE bitset_t *bitset_ ## op(bitset_t *tgt, const bitset_t *src) \
 { \
-       int i; \
-       int n = tgt->units > src->units ? src->units : tgt->units; \
+       unsigned long i; \
+       unsigned long n = tgt->units > src->units ? src->units : tgt->units; \
        for(i = 0; i < n; i += _BITSET_BINOP_UNITS_INC) \
                _bitset_inside_binop_ ## op(&tgt->data[i], &src->data[i]); \
        if(n < tgt->units) \