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

[MooreToCore] Add support for format strings and display task #7694

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

fabianschuiki
Copy link
Contributor

Lower the format string ops and the moore.builtin.display task to the corresponding ops in the Sim dialect. This is not perfect yet, since Sim does not support some of the formatting options. They will be easy to add in the future though.

Base automatically changed from fschuiki/sim-infer-type-op-intf to main October 11, 2024 00:26
Copy link
Member

@hailongSun2000 hailongSun2000 left a comment

Choose a reason for hiding this comment

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

LGTM 🥳!

Lower the format string ops and the `moore.builtin.display` task to the
corresponding ops in the Sim dialect. This is not perfect yet, since Sim
does not support some of the formatting options. They will be easy to
add in the future though.
@fabianschuiki fabianschuiki merged commit dc387c5 into main Oct 11, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/moore-lower-fmt branch October 11, 2024 02:56
// TODO: These should honor the width, alignment, and padding.
switch (op.getFormat()) {
case IntFormat::Decimal:
rewriter.replaceOpWithNewOp<sim::FormatDecOp>(op, adaptor.getValue());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a way of handling signedness here? By not setting the signed attribute the value will always get formatted as unsigned. How would we deal with the difference in this example:

module tb;
  byte foo = 8'h80;
  initial $display("Signed:   %d", $signed(foo));
  initial $display("Unsigned: %d", $unsigned(foo));
endmodule

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great point. Do you know what the standard says how your example would be printed? Does %d check the type's signedness?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any mention of the sign in the LRM. But for once all simulators on edaplayground agree: It depends on the type's signedness. The above example is the same as

module tb;
  logic signed [7:0] fooS = 8'h80;
  logic [7:0] fooU = 8'h80;
  initial $display("Signed:   %d", fooS); // "Signed:   -128"
  initial $display("Unsigned: %d", fooU); // "Unsigned: 128"
endmodule

I wish they'd also agree on the padding...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🎉 Nice! I also love how the %d field expands to the maximum width a decimal number can have, 3, but then adds a random - in front that throws everything off 🤣. I love how SV consistently picks the wrong default for a lot of things.

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

Successfully merging this pull request may close these issues.

3 participants