3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

some micro tuning

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-02-06 16:58:25 -08:00
parent 8b23a1701a
commit 200f47369d
6 changed files with 81 additions and 12 deletions

View file

@ -61,6 +61,9 @@ namespace sat {
else if (n.is_var()) {
SASSERT(!n.sign());
}
else if (n.is_lut()) {
augment_lut(id, n, cs);
}
else if (n.is_ite()) {
augment_ite(id, n, cs);
}
@ -97,6 +100,47 @@ namespace sat {
return true;
}
void aig_cuts::augment_lut(unsigned v, node const& n, cut_set& cs) {
IF_VERBOSE(4, display(verbose_stream() << "augment_lut " << v << " ", n) << "\n");
literal l1 = child(n, 0);
for (auto const& a : m_cuts[l1.var()]) {
m_tables[0] = &a;
cut b(a);
augment_lut_rec(v, n, b, 1, cs);
}
}
void aig_cuts::augment_lut_rec(unsigned v, node const& n, cut& a, unsigned idx, cut_set& cs) {
if (idx < n.size()) {
for (auto const& b : m_cuts[child(n, idx).var()]) {
cut ab;
if (ab.merge(a, b)) {
m_tables[idx] = &b;
augment_lut_rec(v, n, ab, idx + 1, cs);
}
}
return;
}
for (unsigned i = 0; i < n.size(); ++i) {
m_luts[i] = m_tables[i]->shift_table(a);
}
uint64_t r = 0;
SASSERT(a.size() <= 6);
SASSERT(n.size() <= 6);
for (unsigned j = (1u << a.size()); j-- > 0; ) {
unsigned w = 0;
// when computing the output at position j,
// the i'th bit to index into n.lut() is
// based on the j'th output bit in lut[i]
for (unsigned i = n.size(); i-- > 0; ) {
w |= ((m_luts[i] >> j) & 0x1) << i;
}
r |= ((n.lut() >> w) & 0x1) << j;
}
a.set_table(r);
insert_cut(v, a, cs);
}
void aig_cuts::augment_ite(unsigned v, node const& n, cut_set& cs) {
IF_VERBOSE(4, display(verbose_stream() << "augment_ite " << v << " ", n) << "\n");
literal l1 = child(n, 0);

View file

@ -39,6 +39,7 @@ namespace sat {
and_op,
ite_op,
xor_op,
lut_op,
no_op
};
@ -48,6 +49,7 @@ namespace sat {
case and_op: return out << "&";
case ite_op: return out << "?";
case xor_op: return out << "^";
case lut_op: return out << "#";
default: return out << "";
}
}
@ -69,6 +71,7 @@ namespace sat {
class node {
bool m_sign;
bool_op m_op;
uint64_t m_lut;
unsigned m_size;
unsigned m_offset;
public:
@ -78,17 +81,21 @@ namespace sat {
m_sign(false), m_op(var_op), m_size(0), m_offset(v) {}
explicit node(bool sign, bool_op op, unsigned nc, unsigned o) :
m_sign(sign), m_op(op), m_size(nc), m_offset(o) {}
explicit node(uint64_t lut, unsigned nc, unsigned o):
m_sign(false), m_op(lut_op), m_size(nc), m_offset(o) {}
bool is_valid() const { return m_offset != UINT_MAX; }
bool_op op() const { return m_op; }
bool is_var() const { return m_op == var_op; }
bool is_and() const { return m_op == and_op; }
bool is_xor() const { return m_op == xor_op; }
bool is_ite() const { return m_op == ite_op; }
bool is_lut() const { return m_op == lut_op; }
bool is_const() const { return is_and() && size() == 0; }
unsigned var() const { SASSERT(is_var()); return m_offset; }
bool sign() const { return m_sign; }
unsigned size() const { return m_size; }
unsigned offset() const { return m_offset; }
uint64_t lut() const { return m_lut; }
};
random_gen m_rand;
config m_config;
@ -106,6 +113,8 @@ namespace sat {
on_clause_t m_on_clause_add, m_on_clause_del;
cut_set::on_update_t m_on_cut_add, m_on_cut_del;
literal_vector m_clause;
cut const* m_tables[6];
uint64_t m_luts[6];
bool is_touched(bool_var v, node const& n);
bool is_touched(literal lit) const { return is_touched(lit.var()); }
@ -119,12 +128,15 @@ namespace sat {
unsigned_vector filter_valid_nodes() const;
void augment(unsigned_vector const& ids);
void augment(unsigned id, node const& n);
void augment_ite(unsigned v, node const& n, cut_set& cs);
void augment_ite(unsigned v, node const& n, cut_set& cs);
void augment_aig0(unsigned v, node const& n, cut_set& cs);
void augment_aig1(unsigned v, node const& n, cut_set& cs);
void augment_aig2(unsigned v, node const& n, cut_set& cs);
void augment_aigN(unsigned v, node const& n, cut_set& cs);
void augment_lut(unsigned v, node const& n, cut_set& cs);
void augment_lut_rec(unsigned v, node const& n, cut& a, unsigned idx, cut_set& cs);
bool insert_cut(unsigned v, cut const& c, cut_set& cs);
void flush_roots();