1
\$\begingroup\$

In SystemVerilog and in VHDL as well, we can parameterize the length of ports on modules/entities. This means that the bit length of a port can be changed by using a parameter/generic. The required parameter/generic is specified when the module is instantiated.

Is it possible to take a parameter value and pass it to a function that will then return a value that is then used to do the actual parameterization? This could be done explicitly or implicitly.

// Explicit way
register #( .WIDTH(MyFunc(64)) ) D_rg
(
 .clk(clk),
 .rst(rst),
 .wen(1'b1),
 .D(data_in),
 .Q()
);
// Implicit way - this shall call the MyFunc internally on WIDTH parameter
register #( .WIDTH(64) ) D_rg
(
 .clk(clk),
 .rst(rst),
 .wen(1'b1),
 .D(data_in),
 .Q()
);

I believe that the explicit method should be possible, but I am not sure about the implicit method.

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked Dec 8, 2023 at 0:27
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

You can set a parameter by calling a constant function. Refer to IEEE Std 1800-2017, section 13.4.3 Constant functions. There is a long list of restrictions for a function to be considered constant.

This is legal if MyFunc is a constant function:

register #( .WIDTH(MyFunc(64)) ) D_rg

Verilog can not call function MyFunc internally or implicitly with this code:

register #( .WIDTH(64) ) D_rg
answered Dec 8, 2023 at 1:00
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.