You want to match the right hand side width with the declaration width to avoid tool warnings?
First use a 1-bit wide zero constant, this will be expanded using the Verilog expansion rules, which will give you an appropriate width zero:
wire [width-1:0] a_net = 1'b0;
If that generates a simulator/synthesiser warning your tools are outside of the Verilog spec. A common way to get around this is with the replication operator, which can take a constant width:
wire [width-1:0] a_net = {width{1'b0}};
The SystemVerilog generate
statements are elaborated at compile time, they are not procedural code. That means they are processed much like a macro or `ifdef
statement, except that they can evaluate parameters, understand scope, and create new scopes. You need to get rid of the always_comb
construct. The if/else if/else is also a generated block that produces only one row instance per iteration. Assuming n=8, then you will get three generated for-loop blocks named label[0]
, label[1]
, and label[2]
. Your code get elaborated as if you could have written something like the following(assuming n gets overridden to 16.:
module barrel
#(parameter n = 8; parameter control = $clog2(n))
(input logic[n-1:0] data, input logic [control-1:0] select,
output logic [n-1:0] result);
logic [n-1:0] logic[0].tempResult;
logic [n-1:0] logic[1].tempResult;
logic [n-1:0] logic[2].tempResult;
row #(n,1) logic[0].shiftLevel(
data,select[0],label[0].tempResult);
row #(n,2) label[1].shiftLevel(
label[0].tempResult,select[1],label[1].tempResult);
row #(n,4) label[1].shiftLevel(
label[1].tempResult,select[2],label[2].tempResult);
row #(n,8) label[3].shiftLevel(
label[2].tempResult,select[3],result);
endmodule
Note that you could not declare identifiers (the variable names or the module instance names) with the label[x]. prefix without using the generate block construct.
Best Answer
You will get compiling errors with the provided sample code:
tree
is redefined in the same scopewire [1][(WIDTH-1)/1:0][15:0] tree;
is illegalwire [1:1][(WIDTH-1)/1:0][15:0] tree;
is legalYou need to use the generate construct adopted from IEEE1364-2001 that has been extended into SystemVerilog. See IEEE Std 1800-2012 ยง 27 Generate construct for full details on usage.
Using a generate loop will give scope control of the
tree
name since each loop is a sub scope preventing name conflict. adding a label to the loop allows easy referece to the desired scope. What you are looking for is likely:You can access each label via the label identifier loop index. Example:
label[0].tree
has[511/1:0][15:0] tree
label[1].tree
has[511/2:0][15:0] tree
label[8].tree
has[511/256:0][15:0] tree
label[9].tree
has[511/512:0][15:0] tree
If you need the first index, you might want to try:
or: