From 3c9562a4482ec6362c5bd49a3728905ac3ee2b26 Mon Sep 17 00:00:00 2001 From: Daniel Grund Date: Tue, 19 Jul 2005 14:22:51 +0000 Subject: [PATCH] newest biset from libcore [r6243] --- ir/adt/bitset.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ir/adt/bitset.h b/ir/adt/bitset.h index 62f44f9a5..937940cf9 100644 --- a/ir/adt/bitset.h +++ b/ir/adt/bitset.h @@ -245,7 +245,6 @@ static INLINE bitset_pos_t bitset_max(const bitset_t *bs) * @note Note that if pos is set, pos is returned. * @param bs The bitset. * @param pos The bit from which to search for the next set bit. - * @param set if 1, serach for set bits, else for unset bits * @return The next set bit from pos on, or -1, if no set bit was found * after pos. */ @@ -384,6 +383,27 @@ static INLINE int bitset_contains(const bitset_t *lhs, const bitset_t *rhs) return 1; } +/** + * Treat the bitset as a number and subtract 1. + * @param bs The bitset. + * @return The same bitset. + */ +static INLINE void bitset_minus1(bitset_t *bs) +{ +#define _SH (sizeof(bitset_unit_t) * 8 - 1) + + for(i = 0; i < bs->units; ++i) { + bitset_unit_t unit = bs->data[i]; + bitset_unit_t um1 = unit - 1; + + bs->data[i] = um1; + + if(((unit >> _SH) ^ (um1 >> _SH)) == 0) + break; + } +#undef _SH +} + /** * Print a bitset to a stream. * The bitset is printed as a comma seperated list of bits set. -- 2.20.1