144 log(
"Verifying SAT model (%s)..\n", model_undef ?
"with undef" :
"without undef");
148 SatGen satgen(&ez, &sigmap);
149 satgen.model_undef = model_undef;
151 for (
auto &c : module->
cells_)
152 if (!satgen.importCell(c.second))
155 ez.assume(satgen.signals_eq(recorded_set_vars, recorded_set_vals));
157 std::vector<int> y_vec = satgen.importDefSigSpec(module->
wires_.at(
"\\y"));
158 std::vector<bool> y_values;
161 std::vector<int> y_undef_vec = satgen.importUndefSigSpec(module->
wires_.at(
"\\y"));
162 y_vec.insert(y_vec.end(), y_undef_vec.begin(), y_undef_vec.end());
165 log(
" Created SAT problem with %d variables and %d clauses.\n",
166 ez.numCnfVariables(), ez.numCnfClauses());
168 if (!ez.solve(y_vec, y_values))
169 log_error(
"Failed to find solution to SAT problem.\n");
171 for (
int i = 0; i < expected_y.
size(); i++) {
175 if (y_values.at(expected_y.
size()+i))
181 if (solution_bit != expected_bit) {
182 std::string sat_bits, rtl_bits;
183 for (
int k = expected_y.
size()-1; k >= 0; k--) {
184 if (model_undef && y_values.at(expected_y.
size()+k))
187 sat_bits += y_values.at(k) ?
"1" :
"0";
190 log_error(
"Found error in SAT model: y[%d] = %s, should be %s:\n SAT: %s\n RTL: %s\n %*s^\n",
192 sat_bits.c_str(), rtl_bits.c_str(), expected_y.
size()-i-1,
"");
198 std::vector<int> cmp_vars;
199 std::vector<bool> cmp_vals;
201 std::vector<bool> y_undef(y_values.begin() + expected_y.
size(), y_values.end());
203 for (
int i = 0; i < expected_y.
size(); i++)
206 log(
" Toggling undef bit %d to test undef gating.\n", i);
207 if (!ez.solve(y_vec, y_values, ez.IFF(y_vec.at(i), y_values.at(i) ? ez.CONST_FALSE : ez.CONST_TRUE)))
208 log_error(
"Failed to find solution with toggled bit!\n");
210 cmp_vars.push_back(y_vec.at(expected_y.
size() + i));
211 cmp_vals.push_back(
true);
215 cmp_vars.push_back(y_vec.at(i));
216 cmp_vals.push_back(y_values.at(i));
218 cmp_vars.push_back(y_vec.at(expected_y.
size() + i));
219 cmp_vals.push_back(
false);
222 log(
" Testing if SAT solution is unique.\n");
223 ez.assume(ez.vec_ne(cmp_vars, ez.vec_const(cmp_vals)));
224 if (ez.solve(y_vec, y_values))
225 log_error(
"Found two distinct solutions to SAT problem.\n");
229 log(
" Testing if SAT solution is unique.\n");
230 ez.assume(ez.vec_ne(y_vec, ez.vec_const(y_values)));
231 if (ez.solve(y_vec, y_values))
232 log_error(
"Found two distinct solutions to SAT problem.\n");
235 log(
" SAT model verified.\n");
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
void log_error(const char *format,...)
YOSYS_NAMESPACE_BEGIN typedef ezMiniSAT ezDefaultSAT
static const char * id2cstr(const RTLIL::IdString &str)
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
void log(const char *format,...)