3 * Units needed for a given highest bit.
4 * This implementation always allocates units in a multiple of 16 bytes.
5 * @param highest_bit The highest bit that should be storable.
6 * @return The number of units needed.
8 #define _bitset_units(highest_bit) (round_up2(highest_bit, BS_UNIT_SIZE_BITS) / BS_UNIT_SIZE_BITS)
11 * Compute the size in bytes needed for a bitseti, overall.
12 * This also include the size for the bitset data structure.
13 * This implementation computes the size in wat, that the bitset units
14 * can be aligned to 16 bytes.
15 * @param highest_bit The highest bit that shall be storable.
16 * @return The overall amount of bytes needed for that bitset.
18 #define _bitset_overall_size(bitset_base_size,highest_bit) \
19 (bitset_base_size + _bitset_units(highest_bit) * BS_UNIT_SIZE)
22 * calculate the pointer to the data space of the bitset.
23 * @param data The base address of the allocated memory
24 * @param bitset_base_size The size of the basical bitset data structure
25 * which hast to be taken into account.
26 * @param hightest_bit The highest bit that will occur in the bitset.
28 #define _bitset_data_ptr(data,bitset_base_size,highest_bit) \
29 ((unsigned long *) ((char *) data + bitset_base_size))
33 * Clear some units from a certain address on.
34 * @param addr The address from where to clear.
35 * @param n The number of units to set to 0.
37 #define _bitset_inside_clear_units(addr,n) \
38 memset(addr, 0, n * BS_UNIT_SIZE)
41 * Set a bit in a unit.
42 * @param unit A pointer to the unit.
43 * @param bit which bit to set.
45 #define _bitset_inside_set(unit_ptr,bit) (*unit_ptr) |= (1 << (bit))
48 * Clear a bit in a unit.
49 * @param unit A pointer to the unit.
50 * @param bit which bit to set.
52 #define _bitset_inside_clear(unit_ptr,bit) (*unit_ptr) &= ~(1 << (bit))
55 * Flip a bit in a unit.
56 * @param unit A pointer to the unit.
57 * @param bit which bit to set.
59 #define _bitset_inside_flip(unit_ptr,bit) (*unit_ptr) ^= ~(1 << (bit))
62 * Count the number of leading zeroes in a unit.
63 * @param unit A pointer to the unit.
64 * @return The Number of leading zeroes.
66 #define _bitset_inside_nlz(unit_ptr) (nlz(*unit_ptr))
70 * Count the number of trailing zeroes in a unit.
71 * @param unit A pointer to the unit.
72 * @return The Number of leading zeroes.
74 #define _bitset_inside_ntz(unit_ptr) _bitset_std_inside_ntz(unit_ptr)
75 static INLINE int _bitset_std_inside_ntz(unsigned long *unit_ptr)
77 unsigned long data = *unit_ptr;
78 return 32 - nlz(~data & (data - 1));
82 * Count the number of trailing zeroes in a unit (whereas the unit is no
83 * pointer but a value).
85 * @return The Number of leading zeroes.
87 #define _bitset_inside_ntz_value(unit) (32 - nlz(~(unit) & ((unit) - 1)))
90 * test if a bit is set in a unit.
91 * @param unit_ptr The pointer to the unit.
92 * @param bit The bit to check.
93 * @return 1, if the bit is set, 0 otherise.
95 #define _bitset_inside_is_set(unit_ptr,bit) \
96 (((*unit_ptr) & (1 << (bit))) != 0)
99 * count the number of bits set in a unit.
100 * @param unit_ptr The pointer to a unit.
101 * @return The number of bits set in the unit.
103 #define _bitset_inside_pop(unit_ptr) (popcnt(*unit_ptr))
105 #define _BITSET_BINOP_UNITS_INC 1
107 #define _bitset_inside_binop_and(tgt,src) ((*tgt) &= (*src))
108 #define _bitset_inside_binop_andnot(tgt,src) ((*tgt) &= ~(*src))
109 #define _bitset_inside_binop_or(tgt,src) ((*tgt) |= (*src))
110 #define _bitset_inside_binop_xor(tgt,src) ((*tgt) ^= (*src))