3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00

radix sort experiment

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-03-06 13:33:37 -08:00
parent bb4888ce31
commit d3ceb8c794
2 changed files with 30 additions and 0 deletions

View file

@ -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) {

View file

@ -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<std::pair<literal, unsigned>> 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);