0

For instance, I have the following generate block:

localparam N = 4
localparam P = 16
genvar i;
generate 
    for(i=0;i<P;i=i+1)
        begin: dmnGen
        localparam [N-1:0]r = func_r(i);   
        and dmn(OUT[i], S[3][r[3]], S[2][r[2]], S[1][r[1]], S[0][r[0]], EN);
    end
endgenerate

I would like to add S[x][r[x]] inputs to the and gate based on parameter N. Is it possible to programmatically add inputs at compile time?

1
  • no, it is not possible in verilog. But you can always create a script which will generate verilog for you. Commented Mar 16, 2021 at 2:13

1 Answer 1

1

You cannot change the number of port connections based on a parameter. But you can either generate a set of cascading and gates, you better yet, use a reduction & operator.

localparam N = 4
localparam P = 16

genvar i,j;
  for(i=0;i<P;i=i+1) begin: dmnGen
    localparam [N-1:0]r = func_r(i);
    wire [N-1:0] p;
    assign OUT[i] = &p;
    for(j=0;j<N;j=j+1)
     assign p[j] = S[j][r[j]];
  end
endgenerate
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.