X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Fbitset_std.h;h=101c9dc235ca3a31a06df004d125076e36237b92;hb=8c82c6f54cb32864dd266bc1066a50db7bc8c073;hp=b7860ec63eab866002e1c2008a2e4661e366e34b;hpb=90bb79fa74251fbf72b9eca9d60a71b7fff4cf5a;p=libfirm diff --git a/ir/adt/bitset_std.h b/ir/adt/bitset_std.h index b7860ec63..101c9dc23 100644 --- a/ir/adt/bitset_std.h +++ b/ir/adt/bitset_std.h @@ -1,33 +1,45 @@ - -/** - * Units needed for a given highest bit. - * This implementation always allocates units in a multiple of 16 bytes. - * @param highest_bit The highest bit that should be storable. - * @return The number of units needed. +/* + * Copyright (C) 1995-2008 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. */ -#define _bitset_units(highest_bit) (round_up2(highest_bit, BS_UNIT_SIZE_BITS) / BS_UNIT_SIZE_BITS) /** - * Compute the size in bytes needed for a bitseti, overall. - * This also include the size for the bitset data structure. - * This implementation computes the size in wat, that the bitset units - * can be aligned to 16 bytes. - * @param highest_bit The highest bit that shall be storable. - * @return The overall amount of bytes needed for that bitset. + * @file + * @brief ANSI-C compliant implementation of bitsets + * @version $Id$ */ -#define _bitset_overall_size(bitset_base_size,highest_bit) \ - (bitset_base_size + _bitset_units(highest_bit) * BS_UNIT_SIZE) +#ifndef FIRM_ADT_BITSET_STD_H +#define FIRM_ADT_BITSET_STD_H + +#include "bitfiddle.h" + +/** Use ordinary ints as unit types. */ +typedef unsigned int bitset_unit_t; + +#define BITSET_UNIT_FMT "%0x" +#define BITSET_UNIT_ALL_ONE ((unsigned int) -1) /** - * calculate the pointer to the data space of the bitset. - * @param data The base address of the allocated memory - * @param bitset_base_size The size of the basical bitset data structure - * which hast to be taken into account. - * @param hightest_bit The highest bit that will occur in the bitset. + * Clear some units from a certain address on. + * @param addr The address from where to clear. + * @param n The number of units to set to 0. */ -#define _bitset_data_ptr(data,bitset_base_size,highest_bit) \ - ((unsigned long *) ((char *) data + bitset_base_size)) - +#define _bitset_inside_clear_units(addr,n) \ + memset(addr, 0, n * BS_UNIT_SIZE) /** * Set a bit in a unit. @@ -48,7 +60,13 @@ * @param unit A pointer to the unit. * @param bit which bit to set. */ -#define _bitset_inside_flip(unit_ptr,bit) (*unit_ptr) ^= ~(1 << (bit)) +#define _bitset_inside_flip(unit_ptr,bit) (*unit_ptr) ^= (1 << (bit)) + +/** + * Flip a whole unit. + * @param unit_ptr The pointer to the unit. + */ +#define _bitset_inside_flip_unit(unit_ptr) (*unit_ptr) = ~(*unit_ptr) /** * Count the number of leading zeroes in a unit. @@ -64,10 +82,10 @@ * @return The Number of leading zeroes. */ #define _bitset_inside_ntz(unit_ptr) _bitset_std_inside_ntz(unit_ptr) -static INLINE int _bitset_std_inside_ntz(unsigned long *unit_ptr) +static inline unsigned _bitset_std_inside_ntz(bitset_unit_t *unit_ptr) { unsigned long data = *unit_ptr; - return 32 - nlz(~data & (data - 1)); + return 32 - (unsigned) nlz(~data & (data - 1)); } /** @@ -101,7 +119,4 @@ static INLINE int _bitset_std_inside_ntz(unsigned long *unit_ptr) #define _bitset_inside_binop_or(tgt,src) ((*tgt) |= (*src)) #define _bitset_inside_binop_xor(tgt,src) ((*tgt) ^= (*src)) -#define _bitset_inside_binop_with_zero_and(tgt) ((*tgt) &= 0UL) -#define _bitset_inside_binop_with_zero_andnot(tgt) ((*tgt) &= ~0UL) -#define _bitset_inside_binop_with_zero_or(tgt) ((*tgt) |= 0UL) -#define _bitset_inside_binop_with_zero_xor(tgt) ((*tgt) ^= 0UL) +#endif