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 * Set a bit in a unit.
34 * @param unit A pointer to the unit.
35 * @param bit which bit to set.
37 #define _bitset_inside_set(unit_ptr,bit) (*unit_ptr) |= (1 << (bit))
40 * Clear a bit in a unit.
41 * @param unit A pointer to the unit.
42 * @param bit which bit to set.
44 #define _bitset_inside_clear(unit_ptr,bit) (*unit_ptr) &= ~(1 << (bit))
47 * Flip a bit in a unit.
48 * @param unit A pointer to the unit.
49 * @param bit which bit to set.
51 #define _bitset_inside_flip(unit_ptr,bit) (*unit_ptr) ^= ~(1 << (bit))
54 * Count the number of leading zeroes in a unit.
55 * @param unit A pointer to the unit.
56 * @return The Number of leading zeroes.
58 #define _bitset_inside_nlz(unit_ptr) (nlz(*unit_ptr))
62 * Count the number of trailing zeroes in a unit.
63 * @param unit A pointer to the unit.
64 * @return The Number of leading zeroes.
66 #define _bitset_inside_ntz(unit_ptr) _std_bitset_inside_ntz(unit_ptr)
67 static INLINE int _std_bitset_ntz(unsigned long *unit_ptr)
69 unsigned long data = *unit_ptr;
70 return 32 - nlz(~data & (data - 1));
74 * Count the number of trailing zeroes in a unit (whereas the unit is no
75 * pointer but a value).
77 * @return The Number of leading zeroes.
79 #define _bitset_inside_ntz_value(unit) (32 - nlz(~(unit) & ((unit) - 1)))
82 * test if a bit is set in a unit.
83 * @param unit_ptr The pointer to the unit.
84 * @param bit The bit to check.
85 * @return 1, if the bit is set, 0 otherise.
87 #define _bitset_inside_is_set(unit_ptr,bit) \
88 (((*unit_ptr) & (1 << (bit))) != NULL)
91 * count the number of bits set in a unit.
92 * @param unit_ptr The pointer to a unit.
93 * @return The number of bits set in the unit.
95 #define _bitset_inside_pop(unit_ptr) (popcnt(*unit_ptr))
97 #define _BITSET_BINOP_UNITS_INC 1
99 #define _bitset_inside_binop_and(tgt,src) ((*tgt) &= (*src))
100 #define _bitset_inside_binop_andnot(tgt,src) ((*tgt) &= ~(*src))
101 #define _bitset_inside_binop_or(tgt,src) ((*tgt) |= (*src))
102 #define _bitset_inside_binop_xor(tgt,src) ((*tgt) ^= (*src))
104 #define _bitset_inside_binop_with_zero_and(tgt) ((*tgt) &= 0UL)
105 #define _bitset_inside_binop_with_zero_andnot(tgt) ((*tgt) &= ~0UL)
106 #define _bitset_inside_binop_with_zero_or(tgt) ((*tgt) |= 0UL)
107 #define _bitset_inside_binop_with_zero_xor(tgt) ((*tgt) ^= 0UL)