valueset: Remove the unused link field.
[libfirm] / ir / adt / raw_bitset.h
index e5056c4..9cf5894 100644 (file)
@@ -22,7 +22,6 @@
  * @brief   raw bitsets (low-level bitset operations)
  * @date    15.10.2004
  * @author  Matthias Braun
- * @version $Id$
  *
  *     Raw bitsets are constructed from unsigned int arrays. Additional
  *     information like the size of the bitset or the used memory are not
@@ -64,15 +63,10 @@ static inline unsigned *rbitset_malloc(size_t size)
 /**
  * Allocate an empty raw bitset on the stack.
  *
- * @param res   will contain the newly allocated bitset
  * @param size  number of bits in the bitset
  */
-#define rbitset_alloca(res, size) \
-do { \
-       size_t size_bytes = BITSET_SIZE_BYTES(size); \
-       res = (unsigned*)alloca(size_bytes); \
-       memset(res, 0, size_bytes); \
-} while(0)
+#define rbitset_alloca(size) \
+       ((unsigned*)memset(alloca(BITSET_SIZE_BYTES(size)), 0, BITSET_SIZE_BYTES(size)))
 
 /**
  * Allocate an empty raw bitset on an obstack.
@@ -310,6 +304,10 @@ static inline size_t rbitset_next(const unsigned *bitset, size_t pos,
 static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos,
                                       size_t last, bool set)
 {
+       assert(pos <= last);
+       if (pos == last)
+               return (size_t)-1;
+
        size_t p;
        size_t elem_pos = pos / BITS_PER_ELEM;
        size_t bit_pos  = pos % BITS_PER_ELEM;
@@ -324,8 +322,6 @@ static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos,
         */
        unsigned in_elem_mask = (1u << bit_pos) - 1;
 
-       assert(pos < last);
-
        elem ^= mask;
        p = ntz(elem & ~in_elem_mask);
 
@@ -420,7 +416,7 @@ static inline void rbitset_xor(unsigned *dst, const unsigned *src, size_t size)
  * @param bitset   the bitset
  * @param from     first bit to set
  * @param to       last bit (the first bit which is not set anymore)
- * @param val      wether to set to 1 or 0
+ * @param val      whether to set to 1 or 0
  */
 static inline void rbitset_set_range(unsigned *bitset, size_t from,
                                      size_t to, bool val)
@@ -487,7 +483,7 @@ static inline bool rbitsets_equal(const unsigned *bitset1,
 }
 
 /**
- * Tests wether 2 bitsets wether at least 1 bit is set in both.
+ * Tests whether 2 bitsets have at least one common set bit.
  *
  * @param bitset1  the first bitset
  * @param bitset2  the second bitset
@@ -506,7 +502,7 @@ static inline bool rbitsets_have_common(const unsigned *bitset1,
 }
 
 /**
- * Tests wether all bits set in bitset1 are also set in bitset2.
+ * Tests whether all bits set in bitset1 are also set in bitset2.
  *
  * @param bitset1  the first bitset
  * @param bitset2  the second bitset
@@ -568,4 +564,13 @@ static inline void rbitset_copy_into(unsigned *dst, const unsigned *src,
        dst[n-1] = (src[n-1] & last_mask) | (dst[n-1] & ~last_mask);
 }
 
+/**
+ * Convenience macro for raw bitset iteration.
+ * @param bitset The bitset.
+ * @param size   Size of the bitset.
+ * @param elm    A size_t variable.
+ */
+#define rbitset_foreach(bitset, size, elm) \
+       for (size_t elm = 0; (elm = rbitset_next_max((bitset), elm, size, 1)) != (size_t)-1; ++elm)
+
 #endif