add pkgconfig stuff, always build libfirm_xmalloc separately
[libfirm] / ir / adt / raw_bitset.h
index d58c2f1..3a5bfd6 100644 (file)
@@ -1,8 +1,28 @@
+/*
+ * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
 /**
- * @file bitset.h
- * @date 15.10.2004
- * @author Matthias Braun
- * @brief helper functions for working with raw bitsets
+ * @file
+ * @brief   helper functions for working with raw bitsets
+ * @date    15.10.2004
+ * @author  Matthias Braun
+ * @version $Id$
  * @summary
  *     Raw bitsets are constructed from int arrays. Additional information
  *     like the size of the bitset or the used memory aren't saved for
@@ -17,8 +37,8 @@
  *     exactly 32 bits may be put into each element of the array. If there are
  *     remaining bits, then they should be 0
  */
-#ifndef __FIRM_RAW_BITSET_H
-#define __FIRM_RAW_BITSET_H
+#ifndef FIRM_ADT_RAW_BITSET_H
+#define FIRM_ADT_RAW_BITSET_H
 
 #include <assert.h>
 #include "bitset.h"
 #define BITSET_SIZE_BYTES(size_bits)    (BITSET_SIZE_ELEMS(size_bits)*4)
 #define BITSET_ELEM(bitset,pos)         bitset[pos / 32]
 
-static INLINE unsigned *rbitset_alloca(unsigned size)
-{
-       unsigned size_bytes = BITSET_SIZE_BYTES(size);
-       unsigned *res = alloca(size_bytes);
-       memset(res, 0, size_bytes);
-
-       return res;
-}
+/**
+ * Allocate an empty raw bitset on the stack.
+ *
+ * @param res   will contain the newly allocated bitset
+ * @param size  element size of the bitset
+ */
+#define rbitset_alloca(res, size) \
+do { \
+       unsigned size_bytes = BITSET_SIZE_BYTES(size); \
+       res = alloca(size_bytes); \
+       memset(res, 0, size_bytes); \
+} while(0)
 
-static INLINE unsigned *rbitset_obstack_alloc(struct obstack *obst, unsigned size)
-{
+/**
+ * Allocate an empty raw bitset on an obstack.
+ *
+ * @param obst  the obstack where the bitset is allocated on
+ * @param size  element size of the bitset
+ *
+ * @return the new bitset
+ */
+static INLINE unsigned *rbitset_obstack_alloc(struct obstack *obst, unsigned size) {
        unsigned size_bytes = BITSET_SIZE_BYTES(size);
        unsigned *res = obstack_alloc(obst, size_bytes);
        memset(res, 0, size_bytes);
@@ -48,9 +79,18 @@ static INLINE unsigned *rbitset_obstack_alloc(struct obstack *obst, unsigned siz
        return res;
 }
 
+/**
+ * Duplicate a raw bitset on an obstack.
+ *
+ * @param obst       the obstack where the bitset is allocated on
+ * @param old_bitset the bitset to be duplicated
+ * @param size       element size of the bitset
+ *
+ * @return the new bitset
+ */
 static INLINE
 unsigned *rbitset_duplicate_obstack_alloc(struct obstack *obst,
-                                                 const unsigned *old_bitset,
+                                          const unsigned *old_bitset,
                                           unsigned size)
 {
        unsigned size_bytes = BITSET_SIZE_BYTES(size);
@@ -60,23 +100,42 @@ unsigned *rbitset_duplicate_obstack_alloc(struct obstack *obst,
        return res;
 }
 
-static INLINE void rbitset_set(unsigned *bitset, unsigned pos)
-{
+/**
+ * Set a bit at position pos.
+ *
+ * @param bitset  the bitset
+ * @param pos     the position of the bit to be set
+ */
+static INLINE void rbitset_set(unsigned *bitset, unsigned pos) {
        BITSET_ELEM(bitset,pos) |= 1 << (pos % BITS_PER_ELEM);
 }
 
-static INLINE void rbitset_clear(unsigned *bitset, unsigned pos)
-{
+/**
+ * Clear a bit at position pos.
+ *
+ * @param bitset  the bitset
+ * @param pos     the position of the bit to be clear
+ */
+static INLINE void rbitset_clear(unsigned *bitset, unsigned pos) {
        BITSET_ELEM(bitset, pos) &= ~(1 << (pos % BITS_PER_ELEM));
 }
 
-static INLINE int rbitset_is_set(const unsigned *bitset, unsigned pos)
-{
+/**
+ * Check if a bit is set at position pos.
+ *
+ * @param bitset  the bitset
+ * @param pos     the position of the bit to check
+ */
+static INLINE int rbitset_is_set(const unsigned *bitset, unsigned pos) {
        return BITSET_ELEM(bitset, pos) & (1 << (pos % BITS_PER_ELEM));
 }
 
-static INLINE unsigned rbitset_popcnt(const unsigned *bitset, unsigned size)
-{
+/**
+ * Calculate the number of set bits (number of elements).
+ *
+ * @param bitset  the bitset
+ */
+static INLINE unsigned rbitset_popcnt(const unsigned *bitset, unsigned size) {
        unsigned pos;
        unsigned n = BITSET_SIZE_ELEMS(size);
        unsigned res = 0;
@@ -90,8 +149,7 @@ static INLINE unsigned rbitset_popcnt(const unsigned *bitset, unsigned size)
        return res;
 }
 
-static INLINE unsigned rbitset_next(const unsigned *bitset, unsigned pos, int set)
-{
+static INLINE unsigned rbitset_next(const unsigned *bitset, unsigned pos, int set) {
        unsigned p;
        unsigned elem_pos = pos / BITS_PER_ELEM;
        unsigned bit_pos = pos % BITS_PER_ELEM;
@@ -130,60 +188,70 @@ static INLINE unsigned rbitset_next(const unsigned *bitset, unsigned pos, int se
        return 0xdeadbeef;
 }
 
+/**
+ * Inplace Intersection of two sets.
+ */
 static INLINE void rbitset_and(unsigned *bitset1, const unsigned *bitset2,
                                unsigned size)
 {
-       unsigned i = 0;
-       unsigned n = BITSET_SIZE_ELEMS(size);
+       unsigned i, n = BITSET_SIZE_ELEMS(size);
 
        for(i = 0; i < n; ++i) {
                bitset1[i] &= bitset2[i];
        }
 }
 
+/**
+ * Inplace Union of two sets.
+ */
 static INLINE void rbitset_or(unsigned *bitset1, const unsigned *bitset2,
                               unsigned size)
 {
-       unsigned i = 0;
-       unsigned n = BITSET_SIZE_ELEMS(size);
+       unsigned i, n = BITSET_SIZE_ELEMS(size);
 
        for(i = 0; i < n; ++i) {
                bitset1[i] |= bitset2[i];
        }
 }
 
+/**
+ * Remove all bits in bitset2 from bitset 1.
+ */
 static INLINE void rbitset_andnot(unsigned *bitset1, const unsigned *bitset2,
                                   unsigned size)
 {
-       unsigned i = 0;
-       unsigned n = BITSET_SIZE_ELEMS(size);
+       unsigned i, n = BITSET_SIZE_ELEMS(size);
 
        for(i = 0; i < n; ++i) {
                bitset1[i] &= ~bitset2[i];
        }
 }
 
+/**
+ * Xor of two bitsets.
+ */
 static INLINE void rbitset_xor(unsigned *bitset1, const unsigned *bitset2,
                                unsigned size)
 {
-       unsigned i = 0;
-       unsigned n = BITSET_SIZE_ELEMS(size);
+       unsigned i, n = BITSET_SIZE_ELEMS(size);
 
        for(i = 0; i < n; ++i) {
                bitset1[i] ^= bitset2[i];
        }
 }
 
-/** @deprecated */
-static INLINE void rbitset_copy_to_bitset(const unsigned *rbitset, bitset_t *bitset)
-{
+/**
+ * Copy a raw bitset into an bitset.
+ *
+ * @deprecated
+ */
+static INLINE void rbitset_copy_to_bitset(const unsigned *rbitset, bitset_t *bitset) {
        // TODO optimize me (or remove me)
-       unsigned i;
-       unsigned n = bitset_size(bitset);
+       unsigned i, n = bitset_size(bitset);
        for(i = 0; i < n; ++i) {
                if(rbitset_is_set(rbitset, i))
                        bitset_set(bitset, i);
        }
 }
 
-#endif
+#endif /* FIRM_ADT_RAW_BITSET_H */