@@ -1392,7 +1392,7 @@ struct SimWorker : SimShared
13921392 }
13931393 }
13941394
1395- void run (Module *topmod, int numcycles)
1395+ void run (Module *topmod, int cycle_width, int numcycles)
13961396 {
13971397 log_assert (top == nullptr );
13981398 top = new SimInstance (this , scope, topmod);
@@ -1418,20 +1418,20 @@ struct SimWorker : SimShared
14181418 for (int cycle = 0 ; cycle < numcycles; cycle++)
14191419 {
14201420 if (debug)
1421- log (" \n ===== %d =====\n " , 10 *cycle + 5 );
1421+ log (" \n ===== %d =====\n " , int (cycle_width *cycle + cycle_width/ 2 ) );
14221422 else if (verbose)
14231423 log (" Simulating cycle %d.\n " , (cycle*2 )+1 );
14241424 set_inports (clock, State::S0);
14251425 set_inports (clockn, State::S1);
14261426
14271427 update (true );
1428- register_output_step (10 *cycle + 5 );
1428+ register_output_step (cycle_width *cycle + cycle_width/ 2 );
14291429
14301430 if (cycle == 0 )
14311431 top->set_initstate_outputs (State::S0);
14321432
14331433 if (debug)
1434- log (" \n ===== %d =====\n " , 10 *cycle + 10 );
1434+ log (" \n ===== %d =====\n " , int (cycle_width *cycle + cycle_width) );
14351435 else if (verbose)
14361436 log (" Simulating cycle %d.\n " , (cycle*2 )+2 );
14371437
@@ -1444,10 +1444,10 @@ struct SimWorker : SimShared
14441444 }
14451445
14461446 update (true );
1447- register_output_step (10 *cycle + 10 );
1447+ register_output_step (cycle_width *cycle + cycle_width );
14481448 }
14491449
1450- register_output_step (10 *numcycles + 2 );
1450+ register_output_step (cycle_width *numcycles + 2 );
14511451
14521452 write_output_files ();
14531453 }
@@ -1582,7 +1582,7 @@ struct SimWorker : SimShared
15821582 return atoi (name.substr (pos+1 ).c_str ());
15831583 }
15841584
1585- void run_cosim_aiger_witness (Module *topmod)
1585+ void run_cosim_aiger_witness (Module *topmod, int cycle_width )
15861586 {
15871587 log_assert (top == nullptr );
15881588 if (!multiclock && (clock.size ()+clockn.size ())==0 )
@@ -1691,18 +1691,18 @@ struct SimWorker : SimShared
16911691 set_inports (clockn, State::S1);
16921692 }
16931693 update (true );
1694- register_output_step (10 *cycle);
1694+ register_output_step (cycle_width *cycle);
16951695 if (!multiclock && cycle) {
16961696 set_inports (clock, State::S0);
16971697 set_inports (clockn, State::S1);
16981698 update (true );
1699- register_output_step (10 *cycle + 5 );
1699+ register_output_step (cycle_width *cycle + cycle_width/ 2 );
17001700 }
17011701 cycle++;
17021702 break ;
17031703 }
17041704 }
1705- register_output_step (10 *cycle);
1705+ register_output_step (cycle_width *cycle);
17061706 write_output_files ();
17071707 }
17081708
@@ -1730,7 +1730,7 @@ struct SimWorker : SimShared
17301730 return name.substr (0 , pos);
17311731 }
17321732
1733- void run_cosim_btor2_witness (Module *topmod)
1733+ void run_cosim_btor2_witness (Module *topmod, int cycle_width )
17341734 {
17351735 log_assert (top == nullptr );
17361736 if (!multiclock && (clock.size ()+clockn.size ())==0 )
@@ -1768,12 +1768,12 @@ struct SimWorker : SimShared
17681768 set_inports (clock, State::S1);
17691769 set_inports (clockn, State::S0);
17701770 update (true );
1771- register_output_step (10 *cycle+ 0 );
1771+ register_output_step (cycle_width *cycle + 0 );
17721772 if (!multiclock) {
17731773 set_inports (clock, State::S0);
17741774 set_inports (clockn, State::S1);
17751775 update (true );
1776- register_output_step (10 *cycle+ 5 );
1776+ register_output_step (cycle_width *cycle + cycle_width/ 2 );
17771777 }
17781778 cycle++;
17791779 prev_cycle = curr_cycle;
@@ -1832,7 +1832,7 @@ struct SimWorker : SimShared
18321832 break ;
18331833 }
18341834 }
1835- register_output_step (10 *cycle);
1835+ register_output_step (cycle_width *cycle);
18361836 write_output_files ();
18371837 }
18381838
@@ -1983,7 +1983,7 @@ struct SimWorker : SimShared
19831983 }
19841984 }
19851985
1986- void run_cosim_yw_witness (Module *topmod, int append)
1986+ void run_cosim_yw_witness (Module *topmod, int cycle_width, int append)
19871987 {
19881988 if (!clock.empty ())
19891989 log_cmd_error (" The -clock option is not required nor supported when reading a Yosys witness file.\n " );
@@ -2013,7 +2013,7 @@ struct SimWorker : SimShared
20132013 log (" Simulating non-active clock edge.\n " );
20142014 set_yw_clocks (yw, hierarchy, false );
20152015 update (false );
2016- register_output_step (5 );
2016+ register_output_step (cycle_width/ 2 );
20172017 }
20182018 top->set_initstate_outputs (State::S0);
20192019 }
@@ -2026,18 +2026,18 @@ struct SimWorker : SimShared
20262026 set_yw_state (yw, hierarchy, cycle);
20272027 set_yw_clocks (yw, hierarchy, true );
20282028 update (true );
2029- register_output_step (10 * cycle);
2029+ register_output_step (cycle_width* cycle);
20302030
20312031 if (!yw.clocks .empty ()) {
20322032 if (debug)
20332033 log (" Simulating non-active clock edge.\n " );
20342034 set_yw_clocks (yw, hierarchy, false );
20352035 update (false );
2036- register_output_step (5 + 10 * cycle );
2036+ register_output_step (cycle_width*cycle + cycle_width/ 2 );
20372037 }
20382038 }
20392039
2040- register_output_step (10 * (GetSize (yw.steps ) + append));
2040+ register_output_step (cycle_width * (GetSize (yw.steps ) + append));
20412041 write_output_files ();
20422042 }
20432043
@@ -2630,6 +2630,9 @@ struct SimPass : public Pass {
26302630 log (" File formats supported: FST, VCD, AIW, WIT and .yw\n " );
26312631 log (" VCD support requires vcd2fst external tool to be present\n " );
26322632 log (" \n " );
2633+ log (" -width <integer>\n " );
2634+ log (" cycle width in generated simulation output (must be divisible by 2).\n " );
2635+ log (" \n " );
26332636 log (" -append <integer>\n " );
26342637 log (" number of extra clock cycles to simulate for a Yosys witness input\n " );
26352638 log (" \n " );
@@ -2689,6 +2692,7 @@ struct SimPass : public Pass {
26892692 {
26902693 SimWorker worker;
26912694 int numcycles = 20 ;
2695+ int cycle_width = 10 ;
26922696 int append = 0 ;
26932697 bool start_set = false , stop_set = false , at_set = false ;
26942698
@@ -2781,6 +2785,12 @@ struct SimPass : public Pass {
27812785 append = atoi (args[++argidx].c_str ());
27822786 continue ;
27832787 }
2788+ if (args[argidx] == " -width" && argidx+1 < args.size ()) {
2789+ cycle_width = atoi (args[++argidx].c_str ());
2790+ if (cycle_width <= 0 || (cycle_width % 2 ))
2791+ log_cmd_error (" Cycle width must be positive even number.\n " );
2792+ continue ;
2793+ }
27842794 if (args[argidx] == " -map" && argidx+1 < args.size ()) {
27852795 std::string map_filename = args[++argidx];
27862796 rewrite_filename (map_filename);
@@ -2872,7 +2882,7 @@ struct SimPass : public Pass {
28722882 }
28732883
28742884 if (worker.sim_filename .empty ())
2875- worker.run (top_mod, numcycles);
2885+ worker.run (top_mod, cycle_width, numcycles);
28762886 else {
28772887 std::string filename_trim = file_base_name (worker.sim_filename );
28782888 if (filename_trim.size () > 4 && ((filename_trim.compare (filename_trim.size ()-4 , std::string::npos, " .fst" ) == 0 ) ||
@@ -2881,11 +2891,11 @@ struct SimPass : public Pass {
28812891 } else if (filename_trim.size () > 4 && filename_trim.compare (filename_trim.size ()-4 , std::string::npos, " .aiw" ) == 0 ) {
28822892 if (worker.map_filename .empty ())
28832893 log_cmd_error (" For AIGER witness file map parameter is mandatory.\n " );
2884- worker.run_cosim_aiger_witness (top_mod);
2894+ worker.run_cosim_aiger_witness (top_mod, cycle_width );
28852895 } else if (filename_trim.size () > 4 && filename_trim.compare (filename_trim.size ()-4 , std::string::npos, " .wit" ) == 0 ) {
2886- worker.run_cosim_btor2_witness (top_mod);
2896+ worker.run_cosim_btor2_witness (top_mod, cycle_width );
28872897 } else if (filename_trim.size () > 3 && filename_trim.compare (filename_trim.size ()-3 , std::string::npos, " .yw" ) == 0 ) {
2888- worker.run_cosim_yw_witness (top_mod, append);
2898+ worker.run_cosim_yw_witness (top_mod, cycle_width, append);
28892899 } else {
28902900 log_cmd_error (" Unhandled extension for simulation input file `%s`.\n " , worker.sim_filename );
28912901 }
0 commit comments