projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*** empty log message ***
[libfirm]
/
ir
/
adt
/
bitset.h
diff --git
a/ir/adt/bitset.h
b/ir/adt/bitset.h
index
d16d449
..
9ae1637
100644
(file)
--- a/
ir/adt/bitset.h
+++ b/
ir/adt/bitset.h
@@
-16,6
+16,12
@@
#include "firm_config.h"
#include "bitfiddle.h"
#include "firm_config.h"
#include "bitfiddle.h"
+#ifdef _WIN32
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
+
typedef unsigned int bitset_pos_t;
#include "bitset_std.h"
typedef unsigned int bitset_pos_t;
#include "bitset_std.h"
@@
-60,7
+66,7
@@
static INLINE bitset_t *_bitset_prepare(void *area, bitset_pos_t size)
bitset_t *ptr = area;
memset(area, 0, _bitset_overall_size(sizeof(bitset_t), size));
ptr->units = _bitset_units(size);
bitset_t *ptr = area;
memset(area, 0, _bitset_overall_size(sizeof(bitset_t), size));
ptr->units = _bitset_units(size);
- ptr->size = size;
+
ptr->size = size;
ptr->data = _bitset_data_ptr(area, sizeof(bitset_t), size);
return ptr;
}
ptr->data = _bitset_data_ptr(area, sizeof(bitset_t), size);
return ptr;
}
@@
-92,7
+98,7
@@
static INLINE bitset_t *_bitset_mask_highest(bitset_t *bs)
* @param bs The bitset.
* @return The highest bit which can be set or cleared plus 1.
*/
* @param bs The bitset.
* @return The highest bit which can be set or cleared plus 1.
*/
-#define bi
st
et_size(bs) ((bs)->size)
+#define bi
ts
et_size(bs) ((bs)->size)
/**
* Allocate a bitset on an obstack.
/**
* Allocate a bitset on an obstack.
@@
-109,7
+115,7
@@
static INLINE bitset_t *_bitset_mask_highest(bitset_t *bs)
* @return A pointer to an empty initialized bitset.
*/
#define bitset_malloc(size) \
* @return A pointer to an empty initialized bitset.
*/
#define bitset_malloc(size) \
- _bitset_prepare(malloc(_bitset_overall_size(sizeof(bitset_t), size)), size)
+ _bitset_prepare(
x
malloc(_bitset_overall_size(sizeof(bitset_t), size)), size)
/**
* Free a bitset allocated with bitset_malloc().
/**
* Free a bitset allocated with bitset_malloc().
@@
-185,6
+191,18
@@
static INLINE void bitset_flip(bitset_t *bs, bitset_pos_t bit)
_bitset_inside_flip(unit, bit & BS_UNIT_MASK);
}
_bitset_inside_flip(unit, bit & BS_UNIT_MASK);
}
+/**
+ * Flip the whole bitset.
+ * @param bs The bitset.
+ */
+static INLINE void bitset_flip_all(bitset_t *bs)
+{
+ bitset_pos_t i;
+ for(i = 0; i < bs->units; i++)
+ _bitset_inside_flip_unit(&bs->data[i]);
+ _bitset_mask_highest(bs);
+}
+
/**
* Copy a bitset to another.
* @param tgt The target bitset.
/**
* Copy a bitset to another.
* @param tgt The target bitset.
@@
-254,8
+272,9
@@
static INLINE bitset_pos_t _bitset_next(const bitset_t *bs,
bitset_pos_t pos, int set)
{
bitset_pos_t unit_number = pos / BS_UNIT_SIZE_BITS;
bitset_pos_t pos, int set)
{
bitset_pos_t unit_number = pos / BS_UNIT_SIZE_BITS;
+ bitset_pos_t res;
- if(
unit_number >= bs->units
)
+ if(
pos >= bs->size
)
return -1;
{
return -1;
{
@@
-277,8
+296,10
@@
static INLINE bitset_pos_t _bitset_next(const bitset_t *bs,
_bitset_inside_ntz_value((set ? curr_unit : ~curr_unit) & ~in_unit_mask);
/* If there is a bit set in the current unit, exit. */
_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)
- return next_in_this_unit + unit_number * BS_UNIT_SIZE_BITS;
+ if (next_in_this_unit < BS_UNIT_SIZE_BITS) {
+ res = next_in_this_unit + unit_number * BS_UNIT_SIZE_BITS;
+ return res < bs->size ? res : -1;
+ }
/* Else search for set bits in the next units. */
else {
/* Else search for set bits in the next units. */
else {
@@
-288,8
+309,10
@@
static INLINE bitset_pos_t _bitset_next(const bitset_t *bs,
bitset_pos_t first_set =
_bitset_inside_ntz_value(set ? data : ~data);
bitset_pos_t first_set =
_bitset_inside_ntz_value(set ? data : ~data);
- if(first_set < BS_UNIT_SIZE_BITS)
- return first_set + i * BS_UNIT_SIZE_BITS;
+ if (first_set < BS_UNIT_SIZE_BITS) {
+ res = first_set + i * BS_UNIT_SIZE_BITS;
+ return res < bs->size ? res : -1;
+ }
}
}
}
}
}
}