} else if (RewriteRule<ZeroExtendEqConst>::applies(t)) {
res = RewriteRule<ZeroExtendEqConst>::run<false>(t);
}
+ else if (RewriteRule<NormalizeEqPlusNeg>::applies(t))
+ {
+ res = RewriteRule<NormalizeEqPlusNeg>::run<false>(t);
+ }
// if(t.getKind() == kind::EQUAL &&
// ((t[0].getKind() == kind::BITVECTOR_MULT && t[1].getKind() ==
namespace theory {
namespace bv {
-enum RewriteRuleId {
+enum RewriteRuleId
+{
/// core normalization rules
EmptyRule,
OrSimplify,
XorSimplify,
BitwiseSlicing,
+ NormalizeEqPlusNeg,
// rules to simplify bitblasting
BBPlusNeg,
UltPlusOne,
case ConcatToMult: out << "ConcatToMult"; return out;
case IsPowerOfTwo: out << "IsPowerOfTwo"; return out;
case MultSltMult: out << "MultSltMult"; return out;
+ case NormalizeEqPlusNeg: out << "NormalizeEqPlusNeg"; return out;
default:
Unreachable();
}
RewriteRule<SignExtendUltConst> rule126;
RewriteRule<ZeroExtendUltConst> rule127;
RewriteRule<MultSltMult> rule128;
+ RewriteRule<NormalizeEqPlusNeg> rule129;
};
template<> inline
return result;
}
+template <>
+inline bool RewriteRule<NormalizeEqPlusNeg>::applies(TNode node)
+{
+ return node.getKind() == kind::EQUAL
+ && (node[0].getKind() == kind::BITVECTOR_PLUS
+ || node[1].getKind() == kind::BITVECTOR_PLUS);
+}
+
+template <>
+inline Node RewriteRule<NormalizeEqPlusNeg>::apply(TNode node)
+{
+ Debug("bv-rewrite") << "RewriteRule<NormalizeEqPlusNeg>(" << node << ")"
+ << std::endl;
+
+ NodeBuilder<> nb_lhs(kind::BITVECTOR_PLUS);
+ NodeBuilder<> nb_rhs(kind::BITVECTOR_PLUS);
+ NodeManager *nm = NodeManager::currentNM();
+
+ if (node[0].getKind() == kind::BITVECTOR_PLUS)
+ {
+ for (const TNode &n : node[0])
+ {
+ if (n.getKind() == kind::BITVECTOR_NEG)
+ nb_rhs << n[0];
+ else
+ nb_lhs << n;
+ }
+ }
+ else
+ {
+ nb_lhs << node[0];
+ }
+
+ if (node[1].getKind() == kind::BITVECTOR_PLUS)
+ {
+ for (const TNode &n : node[1])
+ {
+ if (n.getKind() == kind::BITVECTOR_NEG)
+ nb_lhs << n[0];
+ else
+ nb_rhs << n;
+ }
+ }
+ else
+ {
+ nb_rhs << node[1];
+ }
+
+ Node zero = utils::mkZero(utils::getSize(node[0]));
+
+ Node lhs, rhs;
+ if (nb_lhs.getNumChildren() == 0)
+ {
+ lhs = zero;
+ }
+ else if (nb_lhs.getNumChildren() == 1)
+ {
+ lhs = nb_lhs[0];
+ }
+ else
+ {
+ lhs = nb_lhs.constructNode();
+ }
+ if (nb_rhs.getNumChildren() == 0)
+ {
+ rhs = zero;
+ }
+ else if (nb_rhs.getNumChildren() == 1)
+ {
+ rhs = nb_rhs[0];
+ }
+ else
+ {
+ rhs = nb_rhs.constructNode();
+ }
+ return nm->mkNode(node.getKind(), lhs, rhs);
+}
+
// template<> inline
// bool RewriteRule<>::applies(TNode node) {
// return (node.getKind() == kind::BITVECTOR_CONCAT);