Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass $display et al. in initial blocks on to sim #4129

Merged
merged 7 commits into from
Jan 11, 2024

Conversation

daglem
Copy link
Contributor

@daglem daglem commented Jan 11, 2024

This cherry picks the completed parts from #3963, cherry picks commits by @whitequark correcting the Verilog backend output of the $print cell and implementing initial $print cells in CXXRTL, and adds the -nodisplay option to read_verilog to optionally suppress elaboration output from $display et al.

Fixes chipsalliance/sv-tests#5082

@daglem daglem requested a review from zachjs as a code owner January 11, 2024 09:50
@whitequark
Copy link
Member

I'm not confident that this should be merged in its current form. I'm currently working on modifying the frontend to emit $check cells, and there is intersection with what this PR is doing (namely, generation of RTLIL for initial assert (...); and later conversion back to Verilog). I think $check and $print cells should be handled uniformly in this aspect.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

I'm not confident that this should be merged in its current form. I'm currently working on modifying the frontend to emit $check cells, and there is intersection with what this PR is doing (namely, generation of RTLIL for initial assert (...); and later conversion back to Verilog). I think $check and $print cells should be handled uniformly in this aspect.

Since the changes in the frontend are so small, could you still consider merging this, and improve on it / rewrite it later?
I'd love to have this working now. And perfect is the enemy of good! 😉

@whitequark
Copy link
Member

whitequark commented Jan 11, 2024

Since the changes in the frontend are so small, could you still consider merging this, and improve on it / rewrite it later?

No. In fact, upon further review, I think #3963 has issues that should be resolved first.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

Since the changes in the frontend are so small, could you still consider merging this, and improve on it / rewrite it later?

No. In fact, upon further review, I think #3963 has issues that should be resolved first.

Sure, but I cherry picked only the first two commits, not the third (unfinished) one. Are there really any controversial changes in the current PR?

@whitequark
Copy link
Member

Are there really any controversial changes in the current PR?

I thought there is at first, but on closer look it seems like the cherry picked commits are OK functionality-wise. If you rename the variable in 97d655a from required to may_fail I'm fine with having it.

4e4d702 should definitely not be merged.

For 0792744, I've added inline comments.

@whitequark
Copy link
Member

Note that this comment:

4e4d702 should definitely not be merged.

directly relates to this comment of mine:

I'm currently working on modifying the frontend to emit $check cells, and there is intersection with what this PR is doing (namely, generation of RTLIL for initial assert (...); and later conversion back to Verilog). I think $check and $print cells should be handled uniformly in this aspect.

So more work will need to be done on $print in initial blocks no matter what. (I'm OK merging this PR excluding the problematic commit in the meantime.)

@whitequark
Copy link
Member

I've narrowed down the cause of the issues with .TRG_POLARITY and currently working on a fix.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

I've narrowed down the cause of the issues with .TRG_POLARITY and currently working on a fix.

Great!

@whitequark
Copy link
Member

You can cherry pick cfbaf18 to have a fix the .TRG_POLARITY issue in this PR.

@whitequark
Copy link
Member

I'm currently working on modifying the frontend to emit $check cells, and there is intersection with what this PR is doing (namely, generation of RTLIL for initial assert (...); and later conversion back to Verilog). I think $check and $print cells should be handled uniformly in this aspect.

There is actually still a bug in the Verilog backend even after my fix: this testcase

module string_format_top;
	parameter STR = "something interesting";
	initial begin
		$display("A: %s", STR);
		$display("B: %0s", STR);
	end
endmodule

is transformed via -b verilog to this code:

(* hdlname = "\\string_format_top" *)
(* top =  1  *)
(* src = "tests/simple/string_format.v:1.1-7.10" *)
module string_format_top();
  (* src = "tests/simple/string_format.v:4.3-4.26" *)
  wire _0_;
  (* src = "tests/simple/string_format.v:5.3-5.27" *)
  wire _1_;
  always @*
    if (1'h1)
      $write("A: %s\n", $unsigned(168'h736f6d657468696e6720696e746572657374696e67));
  always @*
    if (1'h1)
      $write("B: %s\n", $unsigned(168'h736f6d657468696e6720696e746572657374696e67));
  assign _1_ = 1'h1;
  assign _0_ = 1'h1;
endmodule

This is very obviously wrong. However, since this particular bit is entirely unrelated to what this PR is doing, it doesn't need to block this PR.

This allows tools like SBY to capture the $display output independent
from anything else sim might log. Additionally it provides source and
hierarchy locations for everything printed.
@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

You can cherry pick cfbaf18 to have a fix the .TRG_POLARITY issue in this PR.

For some reason I'm not able to cherry pick that - is there some git incantation I have to cast? I have synced my local repository, and I was able to cherry pick the out-of-tree commits above earlier.
Edit: I think I remember what I did now 😅

Done! I've also removed my attempt at a fix.

@whitequark
Copy link
Member

I don't think you pushed it.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

I don't think you pushed it.

Yeah, I just found out 😅

Copy link
Member

@whitequark whitequark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just needs one change I called out inline.

frontends/ast/simplify.cc Outdated Show resolved Hide resolved
@whitequark
Copy link
Member

Please also cherry pick 5579330 since this fixes the bug I described in #4129 (comment).

These are useful for formal verification with SBY where they can be used
to display solver chosen `rand const reg` signals and signals derived
from those.

The previous error message for non-constant initial $display statements
is downgraded to a log message. Constant initial $display statements
will be shown both during elaboration and become part of the RTLIL so
that the `sim` output is complete.
@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

Please also cherry pick 5579330 since this fixes the bug I described in #4129 (comment).

Great, done!

Copy link
Member

@whitequark whitequark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

LGTM

Thanks for all the help!

BTW awesome work on the $print cell, this really brings major improvements to Yosys!

@whitequark
Copy link
Member

Thanks! It was motivated by Amaranth but I implemented it (or at least started that work) in a way that benefits everyone. I do have to say that implementing SystemVerilog semantics correctly took a lot of time and effort...

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

Thanks! It was motivated by Amaranth but I implemented it (or at least started that work) in a way that benefits everyone. I do have to say that implementing SystemVerilog semantics correctly took a lot of time and effort...

I can only imagine! Give yourself a pat on the back, knowing that this would quite possibly never have materialized without your efforts.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

It seems like 5579330 causes tests/fmt/display_lm_tb.cc to fail.

@whitequark
Copy link
Member

That happens because CXXRTL does not (yet) support initial statements with code. It's not clear how or whether to implement that (it would have to be exposed to the record/replay code and the C interface, for one).

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

That happens because CXXRTL does not (yet) support initial statements with code. It's not clear how or whether to implement that (it would have to be exposed to the record/replay code and the C interface, for one).

Can I simply temporarily comment out the initial $display line in the test, seeing that CXXRTL isn't ready for that yet?
Or perhaps you'd rather amend your commit with that (the commenting out, I mean)?
Edit: It seems like the always $display line doesn't work either.

@whitequark
Copy link
Member

Edit: It seems like the always $display line doesn't work either.

That seems to be a bug in CXXRTL.

@whitequark
Copy link
Member

Actually no, it's not. This is the command that fails:

+ grep ^%l: \\bot$ yosys-display_lm.log

This is the testbench output:

$ ./tests/fmt/yosys-display_lm_cc 
%l: \bot
%m: \bot

I think it's a broken testbench. However, while looking at this, I did find a subtle bug in that CXXRTL code.

@whitequark
Copy link
Member

Please cherry-pick commit 388df43.

@whitequark
Copy link
Member

I think it's a broken testbench.

The testbench expects both the synthesis log and the simulation log to contain the output. By commenting out initial $display it is no longer contained in the synthesis log, so the test fails.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

I think it's a broken testbench.

The testbench expects both the synthesis log and the simulation log to contain the output. By commenting out initial $display it is no longer contained in the synthesis log, so the test fails.

Yes, I just found a fix for this - both removing the initial line and changing a line in run-test.sh to
../../yosys -p "read_verilog display_lm.v; hierarchy -auto-top; proc; sim" >yosys-display_lm.log fixes it.

@whitequark
Copy link
Member

I'm not sure that's really the right fix? I'm actually looking at implementing initial $print in CXXRTL right now.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

I'm not sure that's really the right fix? I'm actually looking at implementing initial $print in CXXRTL right now.

Oh, I didn't imagine you'd be attacking that immediately!
I'll just remove my fix then.

@whitequark
Copy link
Member

Cherry-pick 0dd0128.

@daglem
Copy link
Contributor Author

daglem commented Jan 11, 2024

Color me impressed! 😅

@whitequark whitequark merged commit 7825728 into YosysHQ:master Jan 11, 2024
16 checks passed
@daglem
Copy link
Contributor Author

daglem commented Jan 14, 2024

Please also cherry pick 5579330 since this fixes the bug I described in #4129 (comment).

@whitequark Whoops, this commit also completely removes initial $display output from simulation.

@whitequark
Copy link
Member

What is "simulation" here?

@daglem
Copy link
Contributor Author

daglem commented Jan 14, 2024

What is "simulation" here?

In this context, the sim command. See #4131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yosys SV Support Misrepresented Due to $display
3 participants