From c6c085ab2264e99ea0f6ff93669223e21b7033cc Mon Sep 17 00:00:00 2001 From: Maximilien Colange Date: Tue, 22 May 2018 16:07:30 +0200 Subject: [PATCH] various fixes to bitset * spot/misc/bitset.hh: here * tests/core/acc.cc: test it --- spot/misc/bitset.hh | 20 +++++++++++++++----- tests/core/acc.cc | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/spot/misc/bitset.hh b/spot/misc/bitset.hh index 320e2d067..d824e00d3 100644 --- a/spot/misc/bitset.hh +++ b/spot/misc/bitset.hh @@ -115,7 +115,7 @@ namespace spot bool operator>=(const bitset& other) const { - return other.operator>(*this); + return other.operator<=(*this); } bitset operator<<(unsigned s) const @@ -295,19 +295,25 @@ namespace spot unsigned highest() const { - unsigned res = 0; - for (auto v: data) + unsigned res = (N-1)*8*sizeof(word_t); + unsigned i = N; + while (i--) { + auto v = data[i]; if (v == 0) { - res += 8*sizeof(v); + res -= 8*sizeof(word_t); continue; } +#ifdef __GNUC__ + res += 8*sizeof(word_t) - __builtin_clz(v); +#else while (v) { ++res; v >>= 1; } +#endif return res-1; } return 0; @@ -315,7 +321,7 @@ namespace spot unsigned lowest() const { - unsigned res = 0; + unsigned res = 0U; for (auto v: data) { if (v == 0) @@ -323,11 +329,15 @@ namespace spot res += 8*sizeof(v); continue; } +#ifdef __GNUC__ + res += __builtin_ctz(v); +#else while ((v & 1) == 0) { ++res; v >>= 1; } +#endif return res; } return 0; diff --git a/tests/core/acc.cc b/tests/core/acc.cc index 069e0745b..7ac6e5aeb 100644 --- a/tests/core/acc.cc +++ b/tests/core/acc.cc @@ -64,6 +64,9 @@ int main() auto m1 = spot::acc_cond::mark_t({0, 2}); auto m2 = spot::acc_cond::mark_t({0, 3}); auto m3 = spot::acc_cond::mark_t({2, 1}); + auto m4 = spot::acc_cond::mark_t({0, SPOT_NB_ACC-2}); + if (!(m4.min_set() == 1 && m4.max_set() == SPOT_NB_ACC-1)) + return 1; spot::acc_cond::mark_t m0 = {}; std::cout << m0.max_set() << ' ' << m0.min_set() << '\n';