-
Notifications
You must be signed in to change notification settings - Fork 304
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
Conversation
There was a problem hiding this 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.
d6a1312
to
f4211d7
Compare
// TODO: These should honor the width, alignment, and padding. | ||
switch (op.getFormat()) { | ||
case IntFormat::Decimal: | ||
rewriter.replaceOpWithNewOp<sim::FormatDecOp>(op, adaptor.getValue()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
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.