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

SV default input port values #306

Closed
alexforencich opened this issue Feb 18, 2025 · 6 comments
Closed

SV default input port values #306

alexforencich opened this issue Feb 18, 2025 · 6 comments

Comments

@alexforencich
Copy link

SV allows specifying default values for input ports. However, sv2v does not handle these correctly, so tools like quartus complain about the syntax.

Test case:

module mod1 (
    input wire logic in1,
    input wire logic in2 = 1'b1,
    input wire logic in3 = 1'b1,
    output wire logic out
);

assign out = in1 ^ in2 ^ in3;

endmodule

module mod2 (
    input wire logic in1,
    input wire logic in2,
    output wire logic out
);

mod1
mod1_inst (
    .in1(in1),
    .in2(in2),
    .out(out)
);

endmodule

Currently, this converts to:

module mod1 (
    in1,
    in2,
    in3,
    out
);
    input wire in1;
    input wire in2 = 1'b1;
    input wire in3 = 1'b1;
    output wire out;
    assign out = (in1 ^ in2) ^ in3;
endmodule
module mod2 (
    in1,
    in2,
    out
);
    input wire in1;
    input wire in2;
    output wire out;
    mod1 mod1_inst(
	    .in1(in1),
	    .in2(in2),
	    .out(out)
    );
endmodule

But, it should be more like:

module mod1 (
    in1,
    in2,
    in3,
    out
);
    input wire in1;
    input wire in2;
    input wire in3;
    output wire out;
    assign out = (in1 ^ in2) ^ in3;
endmodule
module mod2 (
    in1,
    in2,
    out
);
    input wire in1;
    input wire in2;
    output wire out;
    mod1 mod1_inst(
	    .in1(in1),
	    .in2(in2),
	    .in3(1'b1),
	    .out(out)
    );
endmodule
@zachjs
Copy link
Owner

zachjs commented Feb 23, 2025

Do any of your default input port values depend on parameters or localparams? It would be easier to craft a conversion for this feature if not, thus allowing the expression to be directly substituted into the module instantiation as shown.

@alexforencich
Copy link
Author

Parameters yes in some cases, localparams no (can you even reference localparams in port declarations?). For example, in one case I have a default value like so: '{CNT{8'd12}}. I have done a few tests with default, but it seems some tools don't handle it correctly (IIRC Vivado was not happy with that).

@zachjs
Copy link
Owner

zachjs commented Feb 23, 2025

can you even reference localparams in port declarations?

Yes, of course! The following is perfectly valid:

module top(x);
    localparam W = 10;
    input [W:0] x;
endmodule

Here's a more cursed example where parameters reference localparams:

module mod #(
localparam integer_t LV1 = value_a, LV2 = value_b,
parameter type PT1 = logic,
integer PV1 = 100,
parameter type(PV1) PV2 = PV1 + value_c,
parameter type PT2 = byte_t,
shortint_t PV3 = 4,
localparam LV3 = 5,
type LT1 = byte_t, LT2 = shortint_t
);

@alexforencich
Copy link
Author

Whew. Yeah, I can definitely see how that would make things complicated. Well, stop-gap is at least remove the default value specification from the output completely since that needs to be done either way, and then potentially error out when one of those ports isn't connected somewhere.

@zachjs
Copy link
Owner

zachjs commented Feb 23, 2025

I added support for input ports with default values in 5d5723f. Please let me know if it works for you!

@zachjs
Copy link
Owner

zachjs commented Apr 6, 2025

@alexforencich I'm closing this as completed, as I believe I've implemented the feature you requested. Thank you for the suggestion! Please let me know if you run into any trouble.

@zachjs zachjs closed this as completed Apr 6, 2025
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

No branches or pull requests

2 participants