268 log(
"Eval testing:%c", verbose ?
'\n' :
' ');
272 ConstEval gold_ce(gold_mod), gate_ce(gate_mod);
276 SatGen satgen1(&ez1, &sigmap);
277 SatGen satgen2(&ez2, &sigmap);
278 satgen2.model_undef =
true;
281 for (
auto cell : gold_mod->
cells()) {
282 satgen1.importCell(cell);
283 satgen2.importCell(cell);
286 if (vlog_file.is_open())
288 vlog_file <<
stringf(
"\nmodule %s;\n", uut_name.c_str());
290 for (
auto port : gold_mod->
ports) {
298 vlog_file <<
stringf(
" %s_expr uut_expr(", uut_name.c_str());
304 vlog_file <<
stringf(
" %s_expr uut_noexpr(", uut_name.c_str());
310 vlog_file <<
stringf(
" task run;\n");
311 vlog_file <<
stringf(
" begin\n");
312 vlog_file <<
stringf(
" $display(\"%s\");\n", uut_name.c_str());
315 for (
int i = 0; i < 64; i++)
317 log(verbose ?
"\n" :
".");
323 std::string vlog_pattern_info;
325 for (
auto port : gold_mod->
ports)
339 for (
int i = 0; i <
GetSize(gold_wire); i++)
344 for (
int i = 0; i <
GetSize(gold_wire); i++)
355 gold_ce.set(gold_wire, in_value);
356 gate_ce.set(gate_wire, in_value);
358 if (vlog_file.is_open() &&
GetSize(in_value) > 0) {
360 if (!vlog_pattern_info.empty())
361 vlog_pattern_info +=
" ";
366 if (vlog_file.is_open())
367 vlog_file <<
stringf(
" #1;\n");
369 for (
auto port : gold_mod->
ports)
385 if (!gold_ce.eval(gold_outval))
388 if (!gate_ce.eval(gate_outval))
391 bool gold_gate_mismatch =
false;
392 for (
int i = 0; i <
GetSize(gold_wire); i++) {
395 if (gold_outval[i] == gate_outval[i])
397 gold_gate_mismatch =
true;
401 if (gold_gate_mismatch)
407 out_sig.
append(gold_wire);
408 out_val.
append(gold_outval);
410 if (vlog_file.is_open()) {
411 vlog_file <<
stringf(
" $display(\"[%s] %s expected: %%b, expr: %%b, noexpr: %%b\", %d'b%s, %s_expr, %s_noexpr);\n",
412 vlog_pattern_info.c_str(),
log_id(gold_wire),
GetSize(gold_outval), gold_outval.as_string().c_str(),
log_id(gold_wire),
log_id(gold_wire));
413 vlog_file <<
stringf(
" if (%s_expr !== %d'b%s) begin $display(\"ERROR\"); $finish; end\n",
log_id(gold_wire),
GetSize(gold_outval), gold_outval.as_string().c_str());
414 vlog_file <<
stringf(
" if (%s_noexpr !== %d'b%s) begin $display(\"ERROR\"); $finish; end\n",
log_id(gold_wire),
GetSize(gold_outval), gold_outval.as_string().c_str());
423 std::vector<int> sat1_in_sig = satgen1.importSigSpec(in_sig);
424 std::vector<int> sat1_in_val = satgen1.importSigSpec(in_val);
426 std::vector<int> sat1_model = satgen1.importSigSpec(out_sig);
427 std::vector<bool> sat1_model_value;
429 if (!ez1.solve(sat1_model, sat1_model_value, ez1.vec_eq(sat1_in_sig, sat1_in_val)))
430 log_error(
"Evaluating sat model 1 (no undef modeling) failed!\n");
434 for (
int i =
GetSize(out_sig)-1; i >= 0; i--)
435 log(
"%c", sat1_model_value.at(i) ?
'1' :
'0');
439 for (
int i = 0; i <
GetSize(out_sig); i++) {
440 if (out_val[i] != RTLIL::S0 && out_val[i] !=
RTLIL::S1)
442 if (out_val[i] == RTLIL::S0 && sat1_model_value.at(i) ==
false)
444 if (out_val[i] ==
RTLIL::S1 && sat1_model_value.at(i) ==
true)
446 log_error(
"Mismatch in sat model 1 (no undef modeling) output!\n");
449 std::vector<int> sat2_in_def_sig = satgen2.importDefSigSpec(in_sig);
450 std::vector<int> sat2_in_def_val = satgen2.importDefSigSpec(in_val);
452 std::vector<int> sat2_in_undef_sig = satgen2.importUndefSigSpec(in_sig);
453 std::vector<int> sat2_in_undef_val = satgen2.importUndefSigSpec(in_val);
455 std::vector<int> sat2_model_def_sig = satgen2.importDefSigSpec(out_sig);
456 std::vector<int> sat2_model_undef_sig = satgen2.importUndefSigSpec(out_sig);
458 std::vector<int> sat2_model;
459 sat2_model.insert(sat2_model.end(), sat2_model_def_sig.begin(), sat2_model_def_sig.end());
460 sat2_model.insert(sat2_model.end(), sat2_model_undef_sig.begin(), sat2_model_undef_sig.end());
462 std::vector<bool> sat2_model_value;
464 if (!ez2.solve(sat2_model, sat2_model_value, ez2.vec_eq(sat2_in_def_sig, sat2_in_def_val), ez2.vec_eq(sat2_in_undef_sig, sat2_in_undef_val)))
465 log_error(
"Evaluating sat model 2 (undef modeling) failed!\n");
469 for (
int i =
GetSize(out_sig)-1; i >= 0; i--)
470 log(
"%c", sat2_model_value.at(
GetSize(out_sig) + i) ?
'x' : sat2_model_value.at(i) ?
'1' :
'0');
474 for (
int i = 0; i <
GetSize(out_sig); i++) {
475 if (sat2_model_value.at(
GetSize(out_sig) + i)) {
476 if (out_val[i] != RTLIL::S0 && out_val[i] !=
RTLIL::S1)
479 if (out_val[i] == RTLIL::S0 && sat2_model_value.at(i) ==
false)
481 if (out_val[i] ==
RTLIL::S1 && sat2_model_value.at(i) ==
true)
484 log_error(
"Mismatch in sat model 2 (undef modeling) output!\n");
489 if (vlog_file.is_open()) {
490 vlog_file <<
stringf(
" end\n");
491 vlog_file <<
stringf(
" endtask\n");
492 vlog_file <<
stringf(
"endmodule\n");
RTLIL::Wire * wire(RTLIL::IdString id)
std::string stringf(const char *fmt,...)
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
void log_error(const char *format,...)
YOSYS_NAMESPACE_BEGIN typedef ezMiniSAT ezDefaultSAT
std::vector< RTLIL::IdString > ports
std::string as_string() const
static uint32_t xorshift32(uint32_t limit)
int GetSize(RTLIL::Wire *wire)
#define log_assert(_assert_expr_)
RTLIL::Module * module(RTLIL::IdString name)
RTLIL::ObjRange< RTLIL::Cell * > cells()
void log(const char *format,...)
std::vector< RTLIL::State > bits
std::string as_string() const
void append(const RTLIL::SigSpec &signal)
const char * log_id(RTLIL::IdString str)