diff --git a/src/sat/sat_asymm_branch.cpp b/src/sat/sat_asymm_branch.cpp index 64b1d5e67..40bba0e93 100644 --- a/src/sat/sat_asymm_branch.cpp +++ b/src/sat/sat_asymm_branch.cpp @@ -224,6 +224,22 @@ namespace sat { sort(big, c.begin(), c.end()); } + void asymm_branch::radix_sort(big& big, literal_vector& lits) { + const unsigned d = 4; + const unsigned w = 20; // 1M variable cap + unsigned sz = lits.size(); + m_tmp.reserve(sz); + for (unsigned p = 0; p < w/d; ++p) { + unsigned on[16]; + memset(on, 0, 16*sizeof(unsigned)); + for (literal l : lits) on[(big.get_left(l) >> 4*p) & 15]++; + for (unsigned i = 1; i < 16; ++i) on[i] += on[i-1]; + for (unsigned i = sz; i-- > 0; ) + m_tmp[--on[(big.get_left(lits[i]) >> 4*p) & 15]] = lits[i]; + for (unsigned i = sz; i-- > 0; ) lits[i] = m_tmp[i]; + } + } + void asymm_branch::sort(big& big, literal const* begin, literal const* end) { m_pos.reset(); m_neg.reset(); for (; begin != end; ++begin) { @@ -231,9 +247,20 @@ namespace sat { m_pos.push_back(l); m_neg.push_back(~l); } +#if 0 compare_left cmp(big); std::sort(m_pos.begin(), m_pos.end(), cmp); std::sort(m_neg.begin(), m_neg.end(), cmp); +#else + radix_sort(big, m_pos); + radix_sort(big, m_neg); +#endif + IF_VERBOSE(100, + for (literal l : m_pos) verbose_stream() << big.get_left(l) << " "; + verbose_stream() << "\n"; + for (literal l : m_neg) verbose_stream() << big.get_left(l) << " "; + verbose_stream() << "\n"; + ); } bool asymm_branch::uhte(big& big, clause & c) { diff --git a/src/sat/sat_asymm_branch.h b/src/sat/sat_asymm_branch.h index cc354a5c8..6034ce5f3 100644 --- a/src/sat/sat_asymm_branch.h +++ b/src/sat/sat_asymm_branch.h @@ -51,12 +51,15 @@ namespace sat { unsigned m_tr; literal_vector m_pos, m_neg; // literals (complements of literals) in clauses sorted by discovery time (m_left in BIG). + svector> m_pos1, m_neg1; literal_vector m_to_delete; + literal_vector m_tmp; struct compare_left; void sort(big& big, literal const* begin, literal const* end); void sort(big & big, clause const& c); + void radix_sort(big & big, literal_vector& lits); bool uhle(scoped_detach& scoped_d, big & big, clause & c);