19 ABSL_FLAG(
int, bitset_small_bitset_count, 8,
20 "threshold to count bits with buckets");
26 #define BIT_COUNT_RANGE(size, zero) \ 27 uint##size##_t BitCountRange##size(const uint##size##_t* const bits, \ 28 uint##size##_t start, \ 29 uint##size##_t end) { \ 30 if (end - start > absl::GetFlag(FLAGS_bitset_small_bitset_count)) { \ 31 const int offset_start = BitOffset##size(start); \ 32 const int pos_start = BitPos##size(start); \ 33 const int offset_end = BitOffset##size(end); \ 34 const int pos_end = BitPos##size(end); \ 35 if (offset_end == offset_start) { \ 36 return BitCount##size(bits[offset_start] & \ 37 OneRange##size(pos_start, pos_end)); \ 39 uint##size##_t bit_count = zero; \ 41 BitCount##size(bits[offset_start] & IntervalUp##size(pos_start)); \ 42 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \ 43 bit_count += BitCount##size(bits[offset]); \ 46 BitCount##size(bits[offset_end] & IntervalDown##size(pos_end)); \ 50 uint##size##_t bit_count = zero; \ 51 for (uint##size##_t i = start; i <= end; ++i) { \ 52 bit_count += IsBitSet##size(bits, i); \ 61 #undef BIT_COUNT_RANGE 63 #define IS_EMPTY_RANGE(size) \ 64 bool IsEmptyRange##size(const uint##size##_t* const bits, \ 65 uint##size##_t start, uint##size##_t end) { \ 66 const int offset_start = BitOffset##size(start); \ 67 const int pos_start = BitPos##size(start); \ 68 const int offset_end = BitOffset##size(end); \ 69 const int pos_end = BitPos##size(end); \ 70 if (offset_end == offset_start) { \ 71 if (bits[offset_start] & OneRange##size(pos_start, pos_end)) { \ 75 if (bits[offset_start] & IntervalUp##size(pos_start)) { \ 78 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \ 83 if (bits[offset_end] & IntervalDown##size(pos_end)) { \ 95 #define LEAST_SIGNIFCANT_BIT_POSITION(size) \ 96 int##size##_t LeastSignificantBitPosition##size( \ 97 const uint##size##_t* const bits, uint##size##_t start, \ 98 uint##size##_t end) { \ 99 DCHECK_LE(start, end); \ 100 if (IsBitSet##size(bits, start)) { \ 103 const int offset_start = BitOffset##size(start); \ 104 const int offset_end = BitOffset##size(end); \ 105 const int pos_start = BitPos##size(start); \ 106 if (offset_start == offset_end) { \ 107 const int pos_end = BitPos##size(end); \ 108 const uint##size##_t active_range = \ 109 bits[offset_start] & OneRange##size(pos_start, pos_end); \ 110 if (active_range) { \ 111 return BitShift##size(offset_start) + \ 112 LeastSignificantBitPosition##size(active_range); \ 116 const uint##size##_t start_mask = \ 117 bits[offset_start] & IntervalUp##size(pos_start); \ 119 return BitShift##size(offset_start) + \ 120 LeastSignificantBitPosition##size(start_mask); \ 122 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \ 123 if (bits[offset]) { \ 124 return BitShift##size(offset) + \ 125 LeastSignificantBitPosition##size(bits[offset]); \ 128 const int pos_end = BitPos##size(end); \ 129 const uint##size##_t active_range = \ 130 bits[offset_end] & IntervalDown##size(pos_end); \ 131 if (active_range) { \ 132 return BitShift##size(offset_end) + \ 133 LeastSignificantBitPosition##size(active_range); \ 144 #undef LEAST_SIGNIFCANT_BIT_POSITION 146 #define MOST_SIGNIFICANT_BIT_POSITION(size) \ 147 int##size##_t MostSignificantBitPosition##size( \ 148 const uint##size##_t* const bits, uint##size##_t start, \ 149 uint##size##_t end) { \ 150 DCHECK_GE(end, start); \ 151 if (IsBitSet##size(bits, end)) { \ 154 const int offset_start = BitOffset##size(start); \ 155 const int offset_end = BitOffset##size(end); \ 156 const int pos_end = BitPos##size(end); \ 157 if (offset_start == offset_end) { \ 158 const int pos_start = BitPos##size(start); \ 159 const uint##size##_t active_range = \ 160 bits[offset_start] & OneRange##size(pos_start, pos_end); \ 161 if (active_range) { \ 162 return BitShift##size(offset_end) + \ 163 MostSignificantBitPosition##size(active_range); \ 168 const uint##size##_t end_mask = \ 169 bits[offset_end] & IntervalDown##size(pos_end); \ 171 return BitShift##size(offset_end) + \ 172 MostSignificantBitPosition##size(end_mask); \ 174 for (int offset = offset_end - 1; offset > offset_start; --offset) { \ 175 if (bits[offset]) { \ 176 return BitShift##size(offset) + \ 177 MostSignificantBitPosition##size(bits[offset]); \ 180 const int pos_start = BitPos##size(start); \ 181 const uint##size##_t active_range = \ 182 bits[offset_start] & IntervalUp##size(pos_start); \ 183 if (active_range) { \ 184 return BitShift##size(offset_start) + \ 185 MostSignificantBitPosition##size(active_range); \ 196 #undef MOST_SIGNIFICANT_BIT_POSITION 198 #define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size) \ 199 int##size##_t UnsafeLeastSignificantBitPosition##size( \ 200 const uint##size##_t* const bits, uint##size##_t start, \ 201 uint##size##_t end) { \ 202 DCHECK_LE(start, end); \ 203 DCHECK(IsBitSet##size(bits, end)); \ 204 if (IsBitSet##size(bits, start)) { \ 207 const int offset_start = BitOffset##size(start); \ 208 const int offset_end = BitOffset##size(end); \ 209 const int pos_start = BitPos##size(start); \ 210 const uint##size##_t start_mask = \ 211 bits[offset_start] & IntervalUp##size(pos_start); \ 213 return BitShift##size(offset_start) + \ 214 LeastSignificantBitPosition##size(start_mask); \ 216 for (int offset = offset_start + 1; offset <= offset_end; ++offset) { \ 217 if (bits[offset]) { \ 218 return BitShift##size(offset) + \ 219 LeastSignificantBitPosition##size(bits[offset]); \ 228 #undef UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION 230 #define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size) \ 231 int##size##_t UnsafeMostSignificantBitPosition##size( \ 232 const uint##size##_t* const bits, uint##size##_t start, \ 233 uint##size##_t end) { \ 234 DCHECK_GE(end, start); \ 235 DCHECK(IsBitSet##size(bits, start)); \ 236 if (IsBitSet##size(bits, end)) { \ 239 const int offset_start = BitOffset##size(start); \ 240 const int offset_end = BitOffset##size(end); \ 241 const int pos_end = BitPos##size(end); \ 242 const uint##size##_t end_mask = \ 243 bits[offset_end] & IntervalDown##size(pos_end); \ 245 return BitShift##size(offset_end) + \ 246 MostSignificantBitPosition##size(end_mask); \ 248 for (int offset = offset_end - 1; offset >= offset_start; --offset) { \ 249 if (bits[offset]) { \ 250 return BitShift##size(offset) + \ 251 MostSignificantBitPosition##size(bits[offset]); \ 260 #undef UNSAFE_MOST_SIGNIFICANT_BIT_POSITION #define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size)
ABSL_FLAG(int, bitset_small_bitset_count, 8, "threshold to count bits with buckets")
#define MOST_SIGNIFICANT_BIT_POSITION(size)
#define BIT_COUNT_RANGE(size, zero)
#define IS_EMPTY_RANGE(size)
#define LEAST_SIGNIFCANT_BIT_POSITION(size)
Collection of objects used to extend the Constraint Solver library.
#define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size)