l_en[i] = |l_output_grant[j][i]
overrides the previews assignment. Also, |l_output_grant[j][i]
is a bit-wise or operator to a signal bit, which does nothing.
For the desired functionality use the |=
bit-wise operator; l_en |= l_output_grant[j]
. Alternatively, use the traditional Verilog method l_en = l_en | l_output_grant[j]
. Remember to clear the old values by assign l_en
to all zeros before the for-loops. Failing to clear the values will create latches and prevent any high to low transition from ever happening. Since the widths match the for(i=...)
loop is not needed.
always_comb begin
l_en = '0; // all bits to zero
for(int j=0; j<M; j++) begin
l_en |= l_output_grant[j];
// equivalent to: l_en[0:N-1] = l_en[0:N-1] | l_output_grant[j][0:N-1];
end
end
Note: Use the Verilog style if the synthesizers does not support |=
operator. The simulator will support the operator if SystemVerilog is supported.