43 printf(
"A = %10u (%10d)\n", a, int32_t(a));
44 printf(
"B = %10u (%10d)\n", b, int32_t(b));
47 std::vector<int> va = sat.
vec_var(
"a", 32);
48 std::vector<int> vb = sat.
vec_var(
"b", 32);
53 #define MONITOR_VARS \
54 X(carry) X(overflow) X(sign) X(zero) \
55 X(lt_signed) X(le_signed) X(ge_signed) X(gt_signed) \
56 X(lt_unsigned) X(le_unsigned) X(ge_unsigned) X(gt_unsigned)
58 #define X(_n) int _n; bool _n ## _master;
62 carry_master = ((uint64_t(a) - uint64_t(b)) >> 32) & 1;
63 overflow_master = (int32_t(a) - int32_t(b)) != (int64_t(int32_t(a)) - int64_t(int32_t(b)));
64 sign_master = ((a - b) >> 31) & 1;
69 lt_signed_master = int32_t(a) < int32_t(b);
70 le_signed_master = int32_t(a) <= int32_t(b);
71 ge_signed_master = int32_t(a) >= int32_t(b);
72 gt_signed_master = int32_t(a) > int32_t(b);
74 lt_unsigned_master = a < b;
75 le_unsigned_master = a <= b;
76 ge_unsigned_master = a >= b;
77 gt_unsigned_master = a > b;
89 std::vector<int> modelExpressions;
90 std::vector<bool> modelValues, modelMaster;
91 std::vector<std::string> modelNames;
93 #define X(_n) modelExpressions.push_back(_n); modelNames.push_back(#_n); modelMaster.push_back(_n ## _master);
97 std::vector<int> add_ab = sat.
vec_add(va, vb);
98 std::vector<int> sub_ab = sat.
vec_sub(va, vb);
99 std::vector<int> sub_ba = sat.
vec_sub(vb, va);
105 if (!sat.
solve(modelExpressions, modelValues)) {
106 fprintf(stderr,
"SAT solver failed to find a model!\n");
110 bool found_error =
false;
112 for (
size_t i = 0; i < modelMaster.size(); i++) {
113 if (modelMaster.at(i) != int(modelValues.at(i)))
115 printf(
"%-20s %d%s\n", modelNames.at(i).c_str(), int(modelValues.at(i)),
116 modelMaster.at(i) != modelValues.at(i) ?
" !!!" :
"");
124 printf(
"%-20s %10u %10u%s\n",
"result(a+b)", add_ab_value, a+b, add_ab_value != a+b ?
" !!!" :
"");
125 printf(
"%-20s %10u %10u%s\n",
"result(a-b)", sub_ab_value, a-b, sub_ab_value != a-b ?
" !!!" :
"");
126 printf(
"%-20s %10u %10u%s\n",
"result(b-a)", sub_ba_value, b-a, sub_ba_value != b-a ?
" !!!" :
"");
129 if (found_error || add_ab_value != a+b || sub_ab_value != a-b || sub_ba_value != b-a)
std::vector< int > vec_sub(const std::vector< int > &vec1, const std::vector< int > &vec2)
int vec_ge_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
std::vector< int > vec_var(int numBits)
int vec_le_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
void vec_cmp(const std::vector< int > &vec1, const std::vector< int > &vec2, int &carry, int &overflow, int &sign, int &zero)
int vec_lt_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
void vec_set_unsigned(const std::vector< int > &vec1, uint64_t value)
uint64_t vec_model_get_unsigned(const std::vector< int > &modelExpressions, const std::vector< bool > &modelValues, const std::vector< int > &vec1) const
int vec_gt_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
bool solve(const std::vector< int > &modelExpressions, std::vector< bool > &modelValues, const std::vector< int > &assumptions)
int vec_gt_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
std::vector< int > vec_add(const std::vector< int > &vec1, const std::vector< int > &vec2)
int vec_lt_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
int vec_ge_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
void vec_append(std::vector< int > &vec, const std::vector< int > &vec1) const
int vec_le_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)