Result
unsignedModulus(vector<FixedBits*>& children, FixedBits& output);
+int bvOrF(int a, int b)
+{
+ return a | b;
+}
+
+int bvXOrF(int a, int b)
+{
+ return a ^ b;
+}
+
+int bvAndF(int a, int b)
+{
+ return a &b;
+}
+
+int rightSF(int a, int b)
+{
+ if (b >= sizeof(int)*8)
+ return 0;
+
+ return a>>b;
+}
+
+int leftSF(int a, int b)
+{
+ if (b >= sizeof(int)*8)
+ return 0;
+
+ return a<<b;
+}
+
+int plusF(int a, int b)
+{
+ return a+b;
+}
+
+int multiplyF(int a, int b)
+{
+ return a*b;
+}
+
+int divideF(int a, int b)
+{
+ if (b==0)
+ return 1;
+ return a/b;
+}
+
+
+int subF(int a, int b)
+{
+ return a-b;
+}
+
+int eqF(int a, int b)
+{
+ return (a==b)? 1:0;
+}
+
+int ltF(int a, int b)
+{
+ return (a<b)? 1:0;
+}
+
+int remF(int a, int b)
+{
+ if (b ==0)
+ return a;
+ return (a %b);
+}
struct Functions
Kind k;
string name;
Result (*fn)(vector<FixedBits*>&, FixedBits&);
+ int(*op)(int o1, int o2);
- Function (Kind k_, string name_, Result (*fn_)(vector<FixedBits*>&, FixedBits&) )
+ Function (Kind k_, string name_, Result (*fn_)(vector<FixedBits*>&, FixedBits&), int(*op_)(int o1, int o2) )
{
name = name_;
k = k_;
fn = fn_;
+ op = op_;
}
};
std::list<Function> l;
+ /*
+
+ exhaustively_check(i, BVRIGHTSHIFT, &bvRightShiftBothWays, &rightSF);
+ exhaustively_check(i, BVPLUS, &bvAddBothWays, &plusF);
+
+ exhaustively_check(i, BVAND, &bvAndBothWays, &bvandF);
+ exhaustively_check(i, BVOR, &bvOrBothWays, &bvorF);
+ }
+ */
Functions()
{
- l.push_back(Function(BVSGE, "signed greater than equals", &bvSignedGreaterThanEqualsBothWays));
- l.push_back(Function(BVLT, "unsigned less than", &bvLessThanEqualsBothWays));
- l.push_back(Function(EQ, "equals", &bvEqualsBothWays));
- l.push_back(Function(BVXOR, "bit-vector xor", &bvXorBothWays));
- l.push_back(Function(BVOR, "bit-vector or", &bvOrBothWays));
- l.push_back(Function(BVAND, "bit-vector and", &bvAndBothWays));
- l.push_back(Function(BVRIGHTSHIFT, "right shift", &bvRightShiftBothWays));
- l.push_back(Function(BVLEFTSHIFT, "left shift", &bvLeftShiftBothWays));
- l.push_back(Function(BVSRSHIFT, "arithmetic shift", &bvArithmeticRightShiftBothWays));
- l.push_back(Function(BVPLUS, "addition", &bvAddBothWays));
- l.push_back(Function(BVMULT, "multiplication", &multiply));
- l.push_back(Function(BVDIV, "unsigned division", &unsignedDivide));
- l.push_back(Function(BVMOD, "unsigned remainder", &unsignedModulus));
- l.push_back(Function(SBVDIV, "signed division", &signedDivide));
- l.push_back(Function(SBVREM, "signed remainder",&signedRemainder ));
-}
+ //l.push_back(Function(BVSGE, "signed greater than equals", &bvSignedGreaterThanEqualsBothWays));
+ l.push_back(Function(BVLT, "unsigned less than", &bvLessThanBothWays, <F));
+ l.push_back(Function(EQ, "equals", &bvEqualsBothWays, &eqF));
+ l.push_back(Function(BVXOR, "bit-vector xor", &bvXorBothWays, &bvXOrF));
+ l.push_back(Function(BVOR, "bit-vector or", &bvOrBothWays, &bvOrF ));
+ l.push_back(Function(BVAND, "bit-vector and", &bvAndBothWays, &bvAndF));
+ l.push_back(Function(BVRIGHTSHIFT, "right shift", &bvRightShiftBothWays, &rightSF));
+ l.push_back(Function(BVLEFTSHIFT, "left shift", &bvLeftShiftBothWays, &leftSF));
+ //l.push_back(Function(BVSRSHIFT, "arithmetic shift", &bvArithmeticRightShiftBothWays));
+ l.push_back(Function(BVPLUS, "addition", &bvAddBothWays, &plusF));
+ l.push_back(Function(BVSUB, "subtraction", &bvSubtractBothWays, &subF));
+ l.push_back(Function(BVMULT, "multiplication", &multiply, &multiplyF));
+ l.push_back(Function(BVDIV, "unsigned division", &unsignedDivide, ÷F));
+ l.push_back(Function(BVMOD, "unsigned remainder", &unsignedModulus, &remF));
+ //l.push_back(Function(SBVDIV, "signed division", &signedDivide));
+ //l.push_back(Function(SBVREM, "signed remainder",&signedRemainder ));
+ }
+
#include "StopWatch.h"
#include "Relations.h"
+#include "BBAsProp.h"
+#include "Functions.h"
using simplifier::constantBitP::FixedBits;
using namespace simplifier::constantBitP;
};
void
-exhaustively_check(const int bitwidth, Result (*transfer)(vector<FixedBits*>&, FixedBits&), int (*op)(int a, int b))
+exhaustively_check(const int bitwidth, Kind k, Result (*transfer)(vector<FixedBits*>&, FixedBits&), int (*op)(int a, int b))
{
vector<D> list;
+ int transferBad =0;
+ int BBBad =0;
+
const int numberOfInputParams = 2;
- assert(numberOfInputParams >0);
- const int mask = pow(2, bitwidth) - 1;
+ int resultLength = (is_Form_kind(k) ) ? 1:bitwidth;
+
+ const int input_mask = pow(2, bitwidth) - 1;
+ const int output_mask = resultLength ==1 ? 1: (pow(2, bitwidth)-1);
// Create all the possible inputs, and apply the function.
for (int i = 0; i < pow(2, bitwidth * numberOfInputParams); i++)
{
D d;
- d.a = i & mask;
- d.b = (i >> bitwidth) & mask;
- d.c = op(d.a,d.b) & mask;
+ d.a = i & input_mask;
+ d.b = (i >> bitwidth) & input_mask;
+ d.c = op(d.a,d.b) & output_mask;
list.push_back(d);
}
vector<FixedBits*> temp;
temp.push_back(&a);
temp.push_back(&b);
- FixedBits tempOutput(bitwidth, false);
+
+
+ FixedBits tempOutput(resultLength, false);
vector<int> lengths;
int totalLength = 0;
lengths.push_back(children[i]->getWidth());
}
- int resultLength = tempOutput.getWidth();
+
FixedBits output(resultLength, tempOutput.isBoolean());
lengths.push_back(resultLength);
totalLength += resultLength;
FixedBits empty(bitwidth, false);
- FixedBits c_a(bitwidth, false), c_b(bitwidth, false), c_o(bitwidth, false);
+ FixedBits c_a(bitwidth, false), c_b(bitwidth, false), c_o(resultLength, false);
+
+ BBAsProp BBP(k,mgr,bitwidth);
const int to_iterate = pow(3, totalLength);
for (long j = 0; j < to_iterate; j++)
{
int current = j;
- if (j% 100000 == 0)
- cerr << j << " of " << to_iterate << endl;
+ //if (j% 100000 == 0)
+ // cerr << j << " of " << to_iterate << endl;
int id = 0;
int usedUp = 0;
- for (int k = 0; k < totalLength; k++)
+ for (int k_it = 0; k_it < totalLength; k_it++)
{
- if (k < resultLength)
+ if (k_it < resultLength)
{
- setV(output, k, current % 3);
+ setV(output, k_it, current % 3);
}
else
{
- int working = (k - resultLength - usedUp);
+ int working = (k_it - resultLength - usedUp);
if (working == lengths[id])
{
usedUp += lengths[id];
current /= 3;
}
- bool first = true;
+ bool max_conflict = true;
for (int j = 0; j < list.size(); j++)
{
D& d = list[j];
if (children[0]->unsignedHolds(d.a) && children[1]->unsignedHolds(d.b) && output.unsignedHolds(d.c))
{
- if (first)
+ if (max_conflict)
{
c_a.fromUnsigned(d.a);
c_b.fromUnsigned(d.b);
c_o.fromUnsigned(d.c);
- first = false;
+ max_conflict = false;
}
else
{
}
}
+ const int initialFixed = children[0]->countFixed() + children[1]->countFixed() + output.countFixed();
+ const int maxFixed = c_a.countFixed() + c_b.countFixed() + c_o.countFixed();
+
+
+ BBP.toAssumptions(*children[0], *children[1], output);
+ bool bb_conflict = !BBP.unitPropagate();
+ const int BBFixed = BBP.fixedCount();
+
+ bool transfer_conflict = (transfer(children, output) == CONFLICT) ;
+ const int transferFixed = children[0]->countFixed() + children[1]->countFixed() + output.countFixed();
+
+
+ if (transfer_conflict && !max_conflict)
+ FatalError("!!");
+ if (bb_conflict && !max_conflict)
+ FatalError("~~");
+
+ if (!max_conflict && !bb_conflict)
+ {
+ assert( maxFixed >= BBFixed);
+ assert( initialFixed <= BBFixed);
+ }
+
+ //cerr << "----";
+ // cerr << *children[0] << *children[1] << output << endl;
+ // cerr << c_a << c_b << c_o << endl;
+
+ if (!max_conflict && !transfer_conflict)
+ {
+ assert( maxFixed >= transferFixed);
+ assert( initialFixed <= transferFixed);
+ }
+
+ assert( initialFixed <= maxFixed);
- Result r = transfer(children, output);
- if (r == CONFLICT)
+ if (max_conflict && !transfer_conflict)
+ transferBad++;
+ else if (max_conflict && !bb_conflict)
+ BBBad++;
+ else if (max_conflict)
{
- if(!first)
- FatalError("Not First");
+
}
- else
+ else if (transferFixed != maxFixed)
+ transferBad++;
+ else if (BBFixed != maxFixed)
+ BBBad++;
+
+
+ if (!transfer_conflict && (k != BVMULT) && (k != BVDIV) && (k != BVMOD) )
{
if(!FixedBits::equals(*children[0],c_a))
FatalError("First");
}
for (int i=0; i < children.size();i++)
delete children[i];
-}
-int plusF(int a, int b)
-{
- return a+b;
-}
-
-int subF(int a, int b)
-{
- return a-b;
-}
-
-int leftSF(int a, int b)
-{
- if (b >= sizeof(int)*8)
- return 0;
+ cerr.setf(ios::fixed);
+ cerr << setprecision(1);
+ cerr << "& " << 100 *(transferBad/ (float)to_iterate) << "\\%";
+ cerr << "& " << 100 *(BBBad/ (float)to_iterate) << "\\%";
+ transferBad= 0; BBBad = 0;
- return a<<b;
-}
-
-int rightSF(int a, int b)
-{
- if (b >= sizeof(int)*8)
- return 0;
-
- return a>>b;
-}
-
-int bvandF(int a, int b)
-{
- return a &b;
-}
-
-int bvorF(int a, int b)
-{
- return a | b;
}
void
mgr = &stp;
mgr->UserFlags.disableSimplifications();
mgr->UserFlags.division_by_zero_returns_one_flag = true;
-
- Cpp_interface interface(*mgr, mgr->defaultNodeFactory);
- interface.startup();
+ Cpp_interface interface(*mgr);
srand(time(NULL));
- BEEV::ParserBM = mgr;
+
// Add had a defect effecting bithWidth > 90.
// Shifting had a defect effecting bitWidth > 64.
const int bits = 5;
- if (true)
+ if (false)
{
output << "signed greater than equals" << endl;
go(&bvSignedGreaterThanEqualsBothWays, BVSGE);
output << "multiplication" << endl;
go(&multiply, BVMULT);
-
output << "unsigned division" << endl;
go(&unsignedDivide, BVDIV);
exit(1);
}
- const int exhaustive_bits = 6;
+
+ const int exhaustive_bits = 5;
+
+ Functions f;
+ cerr << "% Automatically generated!!" << endl;
+ cerr << "\\begin{figure} \\centering" <<endl;
+ cerr << "\\begin{tabular}{|c|";
+
+ for (int i = 1; i <= exhaustive_bits; i++)
+ cerr << "c|c|";
+
+ cerr << "} \\hline" << endl;
+
+ cerr << "Operation";
+
+ for (int i = 1; i <= exhaustive_bits; i++)
+ cerr << "& \\multicolumn{2}{c|}{"<< i <<" bits}";
+ cerr << "\\\\ \\hline" << endl;
+
+
+
for (int i = 1; i <= exhaustive_bits; i++)
+ cerr << "& Prop& BB";
+
+ cerr << "\\\\ \\hline" << endl;
+
+ std::list<Functions::Function>::iterator it = f.l.begin();
+ while (it != f.l.end())
{
- exhaustively_check(i, &bvLeftShiftBothWays, &leftSF);
- exhaustively_check(i, &bvRightShiftBothWays, &rightSF);
- exhaustively_check(i, &bvAddBothWays, &plusF);
- exhaustively_check(i, &bvSubtractBothWays, &subF);
- exhaustively_check(i, &bvAndBothWays, &bvandF);
- exhaustively_check(i, &bvOrBothWays, &bvorF);
+ Functions::Function& f = *it;
+ cerr << f.name << endl;
+ for (int i = 1; i <= exhaustive_bits; i++)
+ exhaustively_check(i, f.k, f.fn, f.op);
+ cerr << "\\\\ " << endl;
+ it++;
}
+cerr << "\\hline" ;
+
+ cerr << "\\end{tabular}" <<endl;
+ cerr << "\\caption{Percentage of all the assignments at different bit-widths. Where the Bitblasted encoding and the propagators did missed bits to fix, or missed a conflicting assignment.}" << endl;
+ cerr << "\\end{figure}" <<endl;
+
+exit(1);
if (true)