@@ -130,22 +130,34 @@ class FunctionIOLoweringPassTest : public IrTestBase {
130130 const int64_t output_cycle =
131131 options.input_valid_delay + expected_latency - 1 ;
132132 in_values.resize (num_cycles);
133+ const bool has_reset = pass_options.codegen_options .reset ().has_value ();
134+ const bool has_input_valid = options.input_valid .has_value ();
135+ const int64_t value_offset =
136+ (has_reset ? 1 : 0 ) + (has_input_valid ? 1 : 0 );
133137 XLS_RET_CHECK_EQ (sim_block->GetInputPorts ().size (),
134- (options. input_valid . has_value () ? 1 : 0 ) + inputs.size ());
138+ value_offset + inputs.size ());
135139 for (int64_t i = 0 ; i < sim_block->GetInputPorts ().size (); ++i) {
136140 std::string_view input_name = sim_block->GetInputPorts ()[i]->name ();
137- Value input_value;
138- if (options.input_valid .has_value ()) {
139- if (i == 0 ) {
140- input_value = Value (UBits (1 , 1 ));
141- } else {
142- input_value = inputs[i - 1 ];
141+ if (has_reset && i == 0 ) {
142+ Value reset_disabled = Value (UBits (
143+ pass_options.codegen_options .reset ()->active_low () ? 1 : 0 , 1 ));
144+ for (int64_t j = 0 ; j < num_cycles; ++j) {
145+ in_values[j].emplace (input_name, reset_disabled);
143146 }
147+ continue ;
148+ }
149+
150+ Value input_value;
151+ if (i < value_offset) {
152+ XLS_RET_CHECK (has_input_valid);
153+ XLS_RET_CHECK_EQ (i, value_offset - 1 );
154+ // input_valid should be 1 whenever we have a valid input.
155+ input_value = Value (UBits (1 , 1 ));
144156 } else {
145- input_value = inputs[i];
157+ input_value = inputs[i - value_offset ];
146158 }
147159 for (int64_t j = 0 ; j <= options.input_valid_delay ; ++j) {
148- if (i == 0 && j < options.input_valid_delay ) {
160+ if (i == value_offset - 1 && j < options.input_valid_delay ) {
149161 in_values[j].emplace (input_name, Value (UBits (0 , 1 )));
150162 } else {
151163 in_values[j].emplace (input_name, input_value);
@@ -285,12 +297,13 @@ TEST_F(FunctionIOLoweringPassTest, SingleStageWithIOValid) {
285297 InterpreterResultToStatusOrValue (result));
286298 ASSERT_EQ (expected_output, Value (UBits (42 , 32 )));
287299
288- XLS_ASSERT_OK_AND_ASSIGN (
289- BlockConversionPassOptions options,
290- CreateBlockConversionPassOptions (
291- p.get (), /* pipeline_stages=*/ 1 ,
292- ::xls::verilog::CodegenOptions ().clock_name(" clk" ).valid_control(
293- " x_valid" , " out_valid" )));
300+ XLS_ASSERT_OK_AND_ASSIGN (BlockConversionPassOptions options,
301+ CreateBlockConversionPassOptions (
302+ p.get (), /* pipeline_stages=*/ 1 ,
303+ ::xls::verilog::CodegenOptions ()
304+ .clock_name(" clk" )
305+ .reset(" rst" , false , false , false )
306+ .valid_control(" x_valid" , " out_valid" )));
294307 XLS_ASSERT_OK_AND_ASSIGN (ScheduledBlock * sb,
295308 CreateScheduledBlock (p.get (), " id_func" , options));
296309
@@ -299,7 +312,8 @@ TEST_F(FunctionIOLoweringPassTest, SingleStageWithIOValid) {
299312 IsOkAndHolds (true ));
300313
301314 EXPECT_THAT (sb->GetInputPorts (),
302- ElementsAre (Property (&PortNode::GetName, " x_valid" ),
315+ ElementsAre (Property (&PortNode::GetName, " rst" ),
316+ Property (&PortNode::GetName, " x_valid" ),
303317 Property (&PortNode::GetName, " x" )));
304318 EXPECT_THAT (sb->GetOutputPorts (),
305319 ElementsAre (Property (&PortNode::GetName, " out_valid" ),
@@ -420,12 +434,13 @@ TEST_F(FunctionIOLoweringPassTest, MultiStageWithIOValidDelayed) {
420434 InterpreterResultToStatusOrValue (result));
421435 ASSERT_EQ (expected_output, Value (UBits (42 , 32 )));
422436
423- XLS_ASSERT_OK_AND_ASSIGN (
424- BlockConversionPassOptions options,
425- CreateBlockConversionPassOptions (
426- p.get (), /* pipeline_stages=*/ 3 ,
427- ::xls::verilog::CodegenOptions ().clock_name(" clk" ).valid_control(
428- " x_valid" , " out_valid" )));
437+ XLS_ASSERT_OK_AND_ASSIGN (BlockConversionPassOptions options,
438+ CreateBlockConversionPassOptions (
439+ p.get (), /* pipeline_stages=*/ 3 ,
440+ ::xls::verilog::CodegenOptions ()
441+ .clock_name(" clk" )
442+ .reset(" rst" , false , false , false )
443+ .valid_control(" x_valid" , " out_valid" )));
429444 XLS_ASSERT_OK_AND_ASSIGN (ScheduledBlock * sb,
430445 CreateScheduledBlock (p.get (), " id_func" , options));
431446
@@ -434,7 +449,8 @@ TEST_F(FunctionIOLoweringPassTest, MultiStageWithIOValidDelayed) {
434449 IsOkAndHolds (true ));
435450
436451 EXPECT_THAT (sb->GetInputPorts (),
437- ElementsAre (Property (&PortNode::GetName, " x_valid" ),
452+ ElementsAre (Property (&PortNode::GetName, " rst" ),
453+ Property (&PortNode::GetName, " x_valid" ),
438454 Property (&PortNode::GetName, " x" )));
439455 EXPECT_THAT (sb->GetOutputPorts (),
440456 ElementsAre (Property (&PortNode::GetName, " out_valid" ),
@@ -469,12 +485,13 @@ TEST_F(FunctionIOLoweringPassTest, MultiStageWithIOValid) {
469485 InterpreterResultToStatusOrValue (result));
470486 ASSERT_EQ (expected_output, Value (UBits (42 , 32 )));
471487
472- XLS_ASSERT_OK_AND_ASSIGN (
473- BlockConversionPassOptions options,
474- CreateBlockConversionPassOptions (
475- p.get (), /* pipeline_stages=*/ 3 ,
476- ::xls::verilog::CodegenOptions ().clock_name(" clk" ).valid_control(
477- " x_valid" , " out_valid" )));
488+ XLS_ASSERT_OK_AND_ASSIGN (BlockConversionPassOptions options,
489+ CreateBlockConversionPassOptions (
490+ p.get (), /* pipeline_stages=*/ 3 ,
491+ ::xls::verilog::CodegenOptions ()
492+ .clock_name(" clk" )
493+ .reset(" rst" , false , false , false )
494+ .valid_control(" x_valid" , " out_valid" )));
478495 XLS_ASSERT_OK_AND_ASSIGN (ScheduledBlock * sb,
479496 CreateScheduledBlock (p.get (), " id_func" , options));
480497
@@ -483,7 +500,8 @@ TEST_F(FunctionIOLoweringPassTest, MultiStageWithIOValid) {
483500 IsOkAndHolds (true ));
484501
485502 EXPECT_THAT (sb->GetInputPorts (),
486- ElementsAre (Property (&PortNode::GetName, " x_valid" ),
503+ ElementsAre (Property (&PortNode::GetName, " rst" ),
504+ Property (&PortNode::GetName, " x_valid" ),
487505 Property (&PortNode::GetName, " x" )));
488506 EXPECT_THAT (sb->GetOutputPorts (),
489507 ElementsAre (Property (&PortNode::GetName, " out_valid" ),
@@ -517,12 +535,13 @@ TEST_F(FunctionIOLoweringPassTest, MultiStageMultiInputWithIOValid) {
517535 InterpreterResultToStatusOrValue (result));
518536 ASSERT_EQ (expected_output, Value (UBits (63 , 32 )));
519537
520- XLS_ASSERT_OK_AND_ASSIGN (
521- BlockConversionPassOptions options,
522- CreateBlockConversionPassOptions (
523- p.get (), /* pipeline_stages=*/ 3 ,
524- ::xls::verilog::CodegenOptions ().clock_name(" clk" ).valid_control(
525- " in_valid" , " out_valid" )));
538+ XLS_ASSERT_OK_AND_ASSIGN (BlockConversionPassOptions options,
539+ CreateBlockConversionPassOptions (
540+ p.get (), /* pipeline_stages=*/ 3 ,
541+ ::xls::verilog::CodegenOptions ()
542+ .clock_name(" clk" )
543+ .reset(" rst" , false , false , false )
544+ .valid_control(" in_valid" , " out_valid" )));
526545 XLS_ASSERT_OK_AND_ASSIGN (ScheduledBlock * sb,
527546 CreateScheduledBlock (p.get (), " id_func" , options));
528547
@@ -531,7 +550,8 @@ TEST_F(FunctionIOLoweringPassTest, MultiStageMultiInputWithIOValid) {
531550 IsOkAndHolds (true ));
532551
533552 EXPECT_THAT (sb->GetInputPorts (),
534- ElementsAre (Property (&PortNode::GetName, " in_valid" ),
553+ ElementsAre (Property (&PortNode::GetName, " rst" ),
554+ Property (&PortNode::GetName, " in_valid" ),
535555 Property (&PortNode::GetName, " x" ),
536556 Property (&PortNode::GetName, " y" )));
537557 EXPECT_THAT (sb->GetOutputPorts (),
0 commit comments